@@ -248,31 +248,35 @@ function makeSystemErrorWithCode(key) {
248
248
}
249
249
250
250
function makeNodeErrorWithCode ( Base , key ) {
251
- return class NodeError extends Base {
252
- constructor ( ...args ) {
253
- if ( excludedStackFn === undefined ) {
254
- super ( ) ;
255
- } else {
256
- const limit = Error . stackTraceLimit ;
257
- Error . stackTraceLimit = 0 ;
258
- super ( ) ;
259
- // Reset the limit and setting the name property.
260
- Error . stackTraceLimit = limit ;
261
- }
262
- const message = getMessage ( key , args , this ) ;
263
- ObjectDefineProperty ( this , 'message' , {
264
- value : message ,
265
- enumerable : false ,
266
- writable : true ,
267
- configurable : true
268
- } ) ;
269
- addCodeToName ( this , super . name , key ) ;
270
- this . code = key ;
271
- }
272
-
273
- toString ( ) {
274
- return `${ this . name } [${ key } ]: ${ this . message } ` ;
251
+ return function NodeError ( ...args ) {
252
+ let error ;
253
+ if ( excludedStackFn === undefined ) {
254
+ error = new Base ( ) ;
255
+ } else {
256
+ const limit = Error . stackTraceLimit ;
257
+ Error . stackTraceLimit = 0 ;
258
+ error = new Base ( ) ;
259
+ // Reset the limit and setting the name property.
260
+ Error . stackTraceLimit = limit ;
275
261
}
262
+ const message = getMessage ( key , args , error ) ;
263
+ ObjectDefineProperty ( error , 'message' , {
264
+ value : message ,
265
+ enumerable : false ,
266
+ writable : true ,
267
+ configurable : true ,
268
+ } ) ;
269
+ ObjectDefineProperty ( error , 'toString' , {
270
+ value ( ) {
271
+ return `${ this . name } [${ key } ]: ${ this . message } ` ;
272
+ } ,
273
+ enumerable : false ,
274
+ writable : true ,
275
+ configurable : true ,
276
+ } ) ;
277
+ addCodeToName ( error , Base . name , key ) ;
278
+ error . code = key ;
279
+ return error ;
276
280
} ;
277
281
}
278
282
0 commit comments