@@ -47,7 +47,8 @@ function lazyBuffer() {
4747// and may have .path and .dest.
4848class SystemError extends Error {
4949 constructor ( key , context ) {
50- const prefix = getMessage ( key , [ ] ) ;
50+ super ( ) ;
51+ const prefix = getMessage ( key , [ ] , this ) ;
5152 let message = `${ prefix } : ${ context . syscall } returned ` +
5253 `${ context . code } (${ context . message } )` ;
5354
@@ -56,7 +57,12 @@ class SystemError extends Error {
5657 if ( context . dest !== undefined )
5758 message += ` => ${ context . dest } ` ;
5859
59- super ( message ) ;
60+ Object . defineProperty ( this , 'message' , {
61+ value : message ,
62+ enumerable : false ,
63+ writable : true ,
64+ configurable : true
65+ } ) ;
6066 Object . defineProperty ( this , kInfo , {
6167 configurable : false ,
6268 enumerable : false ,
@@ -150,7 +156,14 @@ let useOriginalName = false;
150156function makeNodeErrorWithCode ( Base , key ) {
151157 return class NodeError extends Base {
152158 constructor ( ...args ) {
153- super ( getMessage ( key , args ) ) ;
159+ super ( ) ;
160+ const message = getMessage ( key , args , this ) ;
161+ Object . defineProperty ( this , 'message' , {
162+ value : message ,
163+ enumerable : false ,
164+ writable : true ,
165+ configurable : true
166+ } ) ;
154167 }
155168
156169 get name ( ) {
@@ -204,7 +217,7 @@ function E(sym, val, def, ...otherClasses) {
204217 codes [ sym ] = def ;
205218}
206219
207- function getMessage ( key , args ) {
220+ function getMessage ( key , args , self ) {
208221 const msg = messages . get ( key ) ;
209222
210223 if ( util === undefined ) util = require ( 'util' ) ;
@@ -216,7 +229,7 @@ function getMessage(key, args) {
216229 `Code: ${ key } ; The provided arguments length (${ args . length } ) does not ` +
217230 `match the required ones (${ msg . length } ).`
218231 ) ;
219- return msg . apply ( null , args ) ;
232+ return msg . apply ( self , args ) ;
220233 }
221234
222235 const expectedLength = ( msg . match ( / % [ d f i j o O s ] / g) || [ ] ) . length ;
@@ -608,8 +621,10 @@ E('ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE',
608621 'The `domain` module is in use, which is mutually exclusive with calling ' +
609622 'process.setUncaughtExceptionCaptureCallback()' ,
610623 Error ) ;
611- E ( 'ERR_ENCODING_INVALID_ENCODED_DATA' ,
612- 'The encoded data was not valid for encoding %s' , TypeError ) ;
624+ E ( 'ERR_ENCODING_INVALID_ENCODED_DATA' , function ( encoding , ret ) {
625+ this . errno = ret ;
626+ return `The encoded data was not valid for encoding ${ encoding } ` ;
627+ } , TypeError ) ;
613628E ( 'ERR_ENCODING_NOT_SUPPORTED' , 'The "%s" encoding is not supported' ,
614629 RangeError ) ;
615630E ( 'ERR_FALSY_VALUE_REJECTION' , 'Promise was rejected with falsy value' , Error ) ;
@@ -652,7 +667,16 @@ E('ERR_HTTP2_INVALID_PSEUDOHEADER',
652667 '"%s" is an invalid pseudoheader or is used incorrectly' , TypeError ) ;
653668E ( 'ERR_HTTP2_INVALID_SESSION' , 'The session has been destroyed' , Error ) ;
654669E ( 'ERR_HTTP2_INVALID_SETTING_VALUE' ,
655- 'Invalid value for setting "%s": %s' , TypeError , RangeError ) ;
670+ // Using default arguments here is important so the arguments are not counted
671+ // towards `Function#length`.
672+ function ( name , actual , min = undefined , max = undefined ) {
673+ this . actual = actual ;
674+ if ( min !== undefined ) {
675+ this . min = min ;
676+ this . max = max ;
677+ }
678+ return `Invalid value for setting "${ name } ": ${ actual } ` ;
679+ } , TypeError , RangeError ) ;
656680E ( 'ERR_HTTP2_INVALID_STREAM' , 'The stream has been destroyed' , Error ) ;
657681E ( 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK' ,
658682 'Maximum number of pending settings acknowledgements' , Error ) ;
@@ -685,7 +709,15 @@ E('ERR_HTTP2_SOCKET_UNBOUND',
685709E ( 'ERR_HTTP2_STATUS_101' ,
686710 'HTTP status code 101 (Switching Protocols) is forbidden in HTTP/2' , Error ) ;
687711E ( 'ERR_HTTP2_STATUS_INVALID' , 'Invalid status code: %s' , RangeError ) ;
688- E ( 'ERR_HTTP2_STREAM_CANCEL' , 'The pending stream has been canceled' , Error ) ;
712+ E ( 'ERR_HTTP2_STREAM_CANCEL' , function ( error ) {
713+ let msg = 'The pending stream has been canceled' ;
714+ if ( error ) {
715+ this . cause = error ;
716+ if ( typeof error . message === 'string' )
717+ msg += ` (caused by: ${ error . message } )` ;
718+ }
719+ return msg ;
720+ } , Error ) ;
689721E ( 'ERR_HTTP2_STREAM_ERROR' , 'Stream closed with error code %s' , Error ) ;
690722E ( 'ERR_HTTP2_STREAM_SELF_DEPENDENCY' ,
691723 'A stream cannot depend on itself' , Error ) ;
@@ -709,7 +741,11 @@ E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error);
709741E ( 'ERR_INSPECTOR_COMMAND' , 'Inspector error %d: %s' , Error ) ;
710742E ( 'ERR_INSPECTOR_NOT_AVAILABLE' , 'Inspector is not available' , Error ) ;
711743E ( 'ERR_INSPECTOR_NOT_CONNECTED' , 'Session is not connected' , Error ) ;
712- E ( 'ERR_INVALID_ADDRESS_FAMILY' , 'Invalid address family: %s' , RangeError ) ;
744+ E ( 'ERR_INVALID_ADDRESS_FAMILY' , function ( addressType , host , port ) {
745+ this . host = host ;
746+ this . port = port ;
747+ return `Invalid address family: ${ addressType } ${ host } :${ port } ` ;
748+ } , RangeError ) ;
713749E ( 'ERR_INVALID_ARG_TYPE' ,
714750 ( name , expected , actual ) => {
715751 assert ( typeof name === 'string' , "'name' must be a string" ) ;
@@ -812,7 +848,10 @@ E('ERR_INVALID_SYNC_FORK_INPUT',
812848E ( 'ERR_INVALID_THIS' , 'Value of "this" must be of type %s' , TypeError ) ;
813849E ( 'ERR_INVALID_TUPLE' , '%s must be an iterable %s tuple' , TypeError ) ;
814850E ( 'ERR_INVALID_URI' , 'URI malformed' , URIError ) ;
815- E ( 'ERR_INVALID_URL' , 'Invalid URL: %s' , TypeError ) ;
851+ E ( 'ERR_INVALID_URL' , function ( input ) {
852+ this . input = input ;
853+ return `Invalid URL: ${ input } ` ;
854+ } , TypeError ) ;
816855E ( 'ERR_INVALID_URL_SCHEME' ,
817856 ( expected ) => `The URL must be ${ oneOf ( expected , 'scheme' ) } ` , TypeError ) ;
818857E ( 'ERR_IPC_CHANNEL_CLOSED' , 'Channel closed' , Error ) ;
@@ -926,8 +965,12 @@ E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode', Error);
926965E ( 'ERR_STREAM_WRITE_AFTER_END' , 'write after end' , Error ) ;
927966E ( 'ERR_SYNTHETIC' , 'JavaScript Callstack' , Error ) ;
928967E ( 'ERR_SYSTEM_ERROR' , 'A system error occurred' , SystemError ) ;
929- E ( 'ERR_TLS_CERT_ALTNAME_INVALID' ,
930- 'Hostname/IP does not match certificate\'s altnames: %s' , Error ) ;
968+ E ( 'ERR_TLS_CERT_ALTNAME_INVALID' , function ( reason , host , cert ) {
969+ this . reason = reason ;
970+ this . host = host ;
971+ this . cert = cert ;
972+ return `Hostname/IP does not match certificate's altnames: ${ reason } ` ;
973+ } , Error ) ;
931974E ( 'ERR_TLS_DH_PARAM_SIZE' , 'DH parameter size %s is less than 2048' , Error ) ;
932975E ( 'ERR_TLS_HANDSHAKE_TIMEOUT' , 'TLS handshake timeout' , Error ) ;
933976E ( 'ERR_TLS_INVALID_PROTOCOL_VERSION' ,
0 commit comments