66// value statically and permanently identifies the error. While the error
77// message may change, the code should not.
88
9- const assert = require ( 'assert' ) ;
109const kCode = Symbol ( 'code' ) ;
1110const messages = new Map ( ) ;
1211
@@ -17,6 +16,13 @@ function lazyUtil() {
1716 return util ;
1817}
1918
19+ var assert ;
20+ function lazyAssert ( ) {
21+ if ( ! assert )
22+ assert = require ( 'assert' ) ;
23+ return assert ;
24+ }
25+
2026function makeNodeError ( Base ) {
2127 return class NodeError extends Base {
2228 constructor ( key , ...args ) {
@@ -36,6 +42,7 @@ function makeNodeError(Base) {
3642}
3743
3844function message ( key , args ) {
45+ const assert = lazyAssert ( ) ;
3946 assert . strictEqual ( typeof key , 'string' ) ;
4047 const util = lazyUtil ( ) ;
4148 const msg = messages . get ( key ) ;
@@ -54,7 +61,6 @@ function message(key, args) {
5461// Utility function for registering the error codes. Only used here. Exported
5562// *only* to allow for testing.
5663function E ( sym , val ) {
57- assert ( messages . has ( sym ) === false , `Error symbol: ${ sym } was already used.` ) ;
5864 messages . set ( sym , typeof val === 'function' ? val : String ( val ) ) ;
5965}
6066
@@ -99,6 +105,7 @@ E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
99105// Add new errors from here...
100106
101107function invalidArgType ( name , expected , actual ) {
108+ const assert = lazyAssert ( ) ;
102109 assert ( name , 'name is required' ) ;
103110 var msg = `The "${ name } " argument must be ${ oneOf ( expected , 'type' ) } ` ;
104111 if ( arguments . length >= 3 ) {
0 commit comments