-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr-unhandled-error.ts
94 lines (87 loc) · 2.18 KB
/
err-unhandled-error.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @file Errors - ERR_UNHANDLED_ERROR
* @module errnode/errors/ERR_UNHANDLED_ERROR
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1807-L1814
*/
import E from '#e'
import { codes } from '#src/enums'
import type {
NodeError,
NodeErrorConstructor,
Stringifiable
} from '#src/interfaces'
/**
* `ERR_UNHANDLED_ERROR` schema.
*
* @see {@linkcode NodeError}
* @see https://nodejs.org/api/errors.html#err_unhandled_error
*
* @extends {NodeError<codes.ERR_UNHANDLED_ERROR>}
*/
interface ErrUnhandledError extends NodeError<codes.ERR_UNHANDLED_ERROR> {}
/**
* `ERR_UNHANDLED_ERROR` message arguments.
*
* @see {@linkcode Stringifiable}
*/
type Args = [err?: Stringifiable | null | undefined]
/**
* `ERR_UNHANDLED_ERROR` constructor.
*
* @see {@linkcode Args}
* @see {@linkcode ErrUnhandledError}
* @see {@linkcode NodeErrorConstructor}
*
* @extends {NodeErrorConstructor<ErrUnhandledError,Args>}
*/
interface ErrUnhandledErrorConstructor
extends NodeErrorConstructor<ErrUnhandledError, Args> {
/**
* Create a new `ERR_UNHANDLED_ERROR` error.
*
* @see {@linkcode ErrUnhandledError}
* @see {@linkcode Stringifiable}
*
* @param {Stringifiable | null | undefined} [err]
* Stringified error
* @return {ErrUnhandledError}
*/
new (err?: Stringifiable | null | undefined): ErrUnhandledError
}
/**
* `ERR_UNHANDLED_ERROR` model.
*
* Thrown when an unhandled error occurs.
*
* @see {@linkcode ErrUnhandledErrorConstructor}
*
* @type {ErrUnhandledErrorConstructor}
*
* @class
*/
const ERR_UNHANDLED_ERROR: ErrUnhandledErrorConstructor = E(
codes.ERR_UNHANDLED_ERROR,
Error,
/**
* @param {Stringifiable | null | undefined} [err]
* Stringified error
* @return {string} Error message
*/
function message(err: Stringifiable | null | undefined = null): string {
/**
* Error message.
*
* @const {string} message
*/
const message: string = 'Unhandled error.'
return err && String(err).length > 0
? `${message} (${String(err)})`
: message
}
)
export {
ERR_UNHANDLED_ERROR as default,
type ErrUnhandledError,
type Args as ErrUnhandledErrorArgs,
type ErrUnhandledErrorConstructor
}