-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr-module-not-found.ts
130 lines (121 loc) · 3.12 KB
/
err-module-not-found.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* @file Errors - ERR_MODULE_NOT_FOUND
* @module errnode/errors/ERR_MODULE_NOT_FOUND
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1581-L1587
*/
import E from '#e'
import { codes } from '#src/enums'
import type {
NodeError,
NodeErrorConstructor,
Stringifiable
} from '#src/interfaces'
/**
* `ERR_MODULE_NOT_FOUND` schema.
*
* @see {@linkcode NodeError}
* @see https://nodejs.org/api/errors.html#err_module_not_found
*
* @extends {NodeError<codes.ERR_MODULE_NOT_FOUND>}
*/
interface ErrModuleNotFound extends NodeError<codes.ERR_MODULE_NOT_FOUND> {
/**
* URL of missing module.
*/
url?: string | null | undefined
}
/**
* `ERR_MODULE_NOT_FOUND` message arguments.
*
* @see {@linkcode Stringifiable}
*/
type Args = [
id: Stringifiable,
base?: Stringifiable | null | undefined,
url?: URL | string | null | undefined
]
/**
* `ERR_MODULE_NOT_FOUND` constructor.
*
* @see {@linkcode Args}
* @see {@linkcode ErrModuleNotFound}
* @see {@linkcode NodeErrorConstructor}
*
* @extends {NodeErrorConstructor<ErrModuleNotFound,Args>}
*/
interface ErrModuleNotFoundConstructor
extends NodeErrorConstructor<ErrModuleNotFound, Args> {
/**
* Create a new `ERR_MODULE_NOT_FOUND` error.
*
* When creating an error for a missing package, `url` should be `null` or
* `undefined`.
*
* @see {@linkcode ErrModuleNotFound}
* @see {@linkcode Stringifiable}
*
* @param {Stringifiable} id
* Id of missing module
* @param {Stringifiable | null | undefined} [base]
* Parent module id
* @param {URL | string | null | undefined} [url]
* Module URL
* @return {ErrModuleNotFound}
*/
new (
id: Stringifiable,
base?: Stringifiable | null | undefined,
url?: URL | string | null | undefined
): ErrModuleNotFound
}
/**
* `ERR_MODULE_NOT_FOUND` model.
*
* Thrown when a module file cannot be resolved by the ECMAScript modules loader
* while attempting an `import` operation or when loading a program entry point.
*
* @see {@linkcode ErrModuleNotFoundConstructor}
*
* @type {ErrModuleNotFoundConstructor}
*
* @class
*/
const ERR_MODULE_NOT_FOUND: ErrModuleNotFoundConstructor = E(
codes.ERR_MODULE_NOT_FOUND,
Error,
/**
* @this {ErrModuleNotFound}
*
* @param {Stringifiable} id
* Id of missing module
* @param {Stringifiable | null | undefined} [base]
* Parent module id
* @param {URL | string | null | undefined} [url]
* Module URL
* @return {string}
* Error message
*/
function message(
this: ErrModuleNotFound,
id: Stringifiable,
base: Stringifiable | null | undefined = null,
url: URL | string | null | undefined = null
): string {
if (url !== null) this.url = String(url)
/**
* Error message.
*
* @var {string} message
*/
let message: string = `Cannot find ${this.url ? 'module' : 'package'}`
message += ` '${String(id)}'`
if (base !== null) message += ` imported from ${String(base)}`
return message
}
)
export {
ERR_MODULE_NOT_FOUND as default,
type ErrModuleNotFound,
type Args as ErrModuleNotFoundArgs,
type ErrModuleNotFoundConstructor
}