Skip to content

Commit a76ff45

Browse files
Copilotsynthable
andcommitted
fix: Add proper type checking for NodeJS error code property
Address code review feedback by ensuring error.code is a string type Co-authored-by: synthable <374893+synthable@users.noreply.github.com>
1 parent d29a9a2 commit a76ff45

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/ums-sdk/src/utils/file-utils.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ describe('file-utils', () => {
3030
expect(isFileNotFoundError(error)).toBe(false);
3131
});
3232

33+
it('should return false for errors with non-string code property', () => {
34+
const error = Object.assign(new Error('Error'), { code: 123 });
35+
expect(isFileNotFoundError(error)).toBe(false);
36+
});
37+
3338
it('should return false for null', () => {
3439
expect(isFileNotFoundError(null)).toBe(false);
3540
});

packages/ums-sdk/src/utils/file-utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { ModuleNotFoundError } from '../errors/index.js';
99
* Type guard to check if an error is a NodeJS ErrnoException
1010
*/
1111
function isNodeError(error: unknown): error is NodeJS.ErrnoException {
12-
return error !== null && typeof error === 'object' && 'code' in error;
12+
return (
13+
error !== null &&
14+
typeof error === 'object' &&
15+
'code' in error &&
16+
typeof (error as { code: unknown }).code === 'string'
17+
);
1318
}
1419

1520
/**

0 commit comments

Comments
 (0)