-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy patherror.ts
More file actions
48 lines (39 loc) · 1.21 KB
/
Copy patherror.ts
File metadata and controls
48 lines (39 loc) · 1.21 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { debug } from './utils/debug'
export class CLIError extends Error {
readonly errorCode: number
readonly message: string
readonly name = 'CLIError'
constructor(message: string, errorCode: number = CLIErrorCode.GENERAL_ERROR) {
super()
this.message = message
this.errorCode = errorCode
}
toString() {
return this.message
}
}
export const CLIErrorCode = {
INVALID_OPTIONS: -1,
GENERAL_ERROR: 1,
NOT_FOUND_BROWSER: 2,
LISTEN_PORT_IS_ALREADY_USED: 3,
CANNOT_SPAWN_SNAP_CHROMIUM: 4,
NOT_FOUND_SOFFICE: 5,
/** @deprecated NOT_FOUND_CHROMIUM is renamed to NOT_FOUND_BROWSER. */
NOT_FOUND_CHROMIUM: 2,
} as const
export function error(
msg: string,
errorCode: number = CLIErrorCode.GENERAL_ERROR
): never {
const cliError = new CLIError(msg, errorCode)
debug('%O', cliError)
throw cliError
}
// TODO: Use Error.isError instead, in Node.js v24.3+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError
export const isError = (e: unknown): e is NodeJS.ErrnoException => {
if (e instanceof Error) return true
const tag = Object.prototype.toString.call(e)
return tag === '[object Error]' || /^\[object .+Error\]$/i.test(tag)
}