Skip to content

Commit d3306e0

Browse files
fix: use Status enum for status code in ServiceError type guards
This change resolves the issue where the intersection of `ServiceError` error codes of type `number` resulted in the `never` type due to conflict between number and `State` enum if `StatusObject`
1 parent 3ccc864 commit d3306e0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arduino-ide-extension/src/node/service-error.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Metadata, StatusObject } from '@grpc/grpc-js';
22
import { Status } from './cli-protocol/google/rpc/status_pb';
33
import { stringToUint8Array } from '../common/utils';
4+
import { Status as StatusCode } from '@grpc/grpc-js/build/src/constants';
45
import { ProgrammerIsRequiredForUploadError } from './cli-protocol/cc/arduino/cli/commands/v1/upload_pb';
56

67
type ProtoError = typeof ProgrammerIsRequiredForUploadError;
@@ -14,7 +15,9 @@ const protoErrorsMap = new Map<string, ProtoError>([
1415

1516
export type ServiceError = StatusObject & Error;
1617
export namespace ServiceError {
17-
export function isCancel(arg: unknown): arg is ServiceError & { code: 1 } {
18+
export function isCancel(
19+
arg: unknown
20+
): arg is ServiceError & { code: StatusCode.CANCELLED } {
1821
return is(arg) && arg.code === 1; // https://grpc.github.io/grpc/core/md_doc_statuscodes.html
1922
}
2023

0 commit comments

Comments
 (0)