-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy patherrors.ts
34 lines (32 loc) · 1.13 KB
/
errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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';
}
}