-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generalized Node.js error handling
gracefully handle when sketch folder has been deleted Closes #1596 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
- Loading branch information
Akos Kitta
committed
Nov 2, 2022
1 parent
f6275f9
commit 12fff33
Showing
5 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export type ErrnoException = Error & { code: string; errno: number }; | ||
export namespace ErrnoException { | ||
export function is(arg: unknown): arg is ErrnoException { | ||
if (arg instanceof Error) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const error = arg as any; | ||
return ( | ||
'code' in error && | ||
'errno' in error && | ||
typeof error['code'] === 'string' && | ||
typeof error['errno'] === 'number' | ||
); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* (No such file or directory): Commonly raised by `fs` operations to indicate that a component of the specified pathname does not exist — no entity (file or directory) could be found by the given path. | ||
*/ | ||
export function isENOENT( | ||
arg: unknown | ||
): arg is ErrnoException & { code: 'ENOENT' } { | ||
return is(arg) && arg.code === 'ENOENT'; | ||
} | ||
|
||
/** | ||
* (Not a directory): A component of the given pathname existed, but was not a directory as expected. Commonly raised by `fs.readdir`. | ||
*/ | ||
export function isENOTDIR( | ||
arg: unknown | ||
): arg is ErrnoException & { code: 'ENOTDIR' } { | ||
return is(arg) && arg.code === 'ENOTDIR'; | ||
} | ||
} |