6
6
// value statically and permanently identifies the error. While the error
7
7
// message may change, the code should not.
8
8
9
- const assert = require ( 'assert' ) ;
10
9
const kCode = Symbol ( 'code' ) ;
11
10
const messages = new Map ( ) ;
12
11
@@ -17,6 +16,13 @@ function lazyUtil() {
17
16
return util ;
18
17
}
19
18
19
+ var assert ;
20
+ function lazyAssert ( ) {
21
+ if ( ! assert )
22
+ assert = require ( 'assert' ) ;
23
+ return assert ;
24
+ }
25
+
20
26
function makeNodeError ( Base ) {
21
27
return class NodeError extends Base {
22
28
constructor ( key , ...args ) {
@@ -36,6 +42,7 @@ function makeNodeError(Base) {
36
42
}
37
43
38
44
function message ( key , args ) {
45
+ const assert = lazyAssert ( ) ;
39
46
assert . strictEqual ( typeof key , 'string' ) ;
40
47
const util = lazyUtil ( ) ;
41
48
const msg = messages . get ( key ) ;
@@ -54,7 +61,6 @@ function message(key, args) {
54
61
// Utility function for registering the error codes. Only used here. Exported
55
62
// *only* to allow for testing.
56
63
function E ( sym , val ) {
57
- assert ( messages . has ( sym ) === false , `Error symbol: ${ sym } was already used.` ) ;
58
64
messages . set ( sym , typeof val === 'function' ? val : String ( val ) ) ;
59
65
}
60
66
@@ -99,6 +105,7 @@ E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
99
105
// Add new errors from here...
100
106
101
107
function invalidArgType ( name , expected , actual ) {
108
+ const assert = lazyAssert ( ) ;
102
109
assert ( name , 'name is required' ) ;
103
110
var msg = `The "${ name } " argument must be ${ oneOf ( expected , 'type' ) } ` ;
104
111
if ( arguments . length >= 3 ) {
0 commit comments