1
1
'use strict' ;
2
2
3
+ const errors = require ( 'internal/errors' ) ;
3
4
const StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
4
5
const EventEmitter = require ( 'events' ) ;
5
6
const net = require ( 'net' ) ;
@@ -367,6 +368,7 @@ function onErrorNT(self, err) {
367
368
368
369
369
370
ChildProcess . prototype . kill = function ( sig ) {
371
+
370
372
const signal = sig === 0 ? sig :
371
373
convertToValidSignal ( sig === undefined ? 'SIGTERM' : sig ) ;
372
374
@@ -538,15 +540,15 @@ function setupChannel(target, channel) {
538
540
options = undefined ;
539
541
} else if ( options !== undefined &&
540
542
( options === null || typeof options !== 'object' ) ) {
541
- throw new TypeError ( '" options" argument must be an object ' ) ;
543
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , ' options' , 'Object ') ;
542
544
}
543
545
544
546
options = Object . assign ( { swallowErrors : false } , options ) ;
545
547
546
548
if ( this . connected ) {
547
549
return this . _send ( message , handle , options , callback ) ;
548
550
}
549
- const ex = new Error ( 'channel closed ' ) ;
551
+ const ex = new errors . Error ( 'ERR_IPC_CHANNEL_CLOSED ' ) ;
550
552
if ( typeof callback === 'function' ) {
551
553
process . nextTick ( callback , ex ) ;
552
554
} else {
@@ -559,7 +561,7 @@ function setupChannel(target, channel) {
559
561
assert ( this . connected || this . channel ) ;
560
562
561
563
if ( message === undefined )
562
- throw new TypeError ( '"message" argument cannot be undefined ' ) ;
564
+ throw new errors . TypeError ( 'ERR_MISSING_ARGS' , 'message ') ;
563
565
564
566
// Support legacy function signature
565
567
if ( typeof options === 'boolean' ) {
@@ -586,7 +588,7 @@ function setupChannel(target, channel) {
586
588
} else if ( handle instanceof UDP ) {
587
589
message . type = 'dgram.Native' ;
588
590
} else {
589
- throw new TypeError ( 'This handle type can\'t be sent ' ) ;
591
+ throw new errors . TypeError ( 'ERR_INVALID_HANDLE_TYPE ' ) ;
590
592
}
591
593
592
594
// Queue-up message and handle if we haven't received ACK yet.
@@ -686,7 +688,7 @@ function setupChannel(target, channel) {
686
688
687
689
target . disconnect = function ( ) {
688
690
if ( ! this . connected ) {
689
- this . emit ( 'error' , new Error ( 'IPC channel is already disconnected ' ) ) ;
691
+ this . emit ( 'error' , new errors . Error ( 'ERR_IPC_DISCONNECTED ' ) ) ;
690
692
return ;
691
693
}
692
694
@@ -766,11 +768,12 @@ function _validateStdio(stdio, sync) {
766
768
case 'ignore' : stdio = [ 'ignore' , 'ignore' , 'ignore' ] ; break ;
767
769
case 'pipe' : stdio = [ 'pipe' , 'pipe' , 'pipe' ] ; break ;
768
770
case 'inherit' : stdio = [ 0 , 1 , 2 ] ; break ;
769
- default : throw new TypeError ( 'Incorrect value of stdio option: ' + stdio ) ;
771
+ default :
772
+ throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE' , 'stdio' , stdio ) ;
770
773
}
771
774
} else if ( ! Array . isArray ( stdio ) ) {
772
- throw new TypeError ( 'Incorrect value of stdio option: ' +
773
- util . inspect ( stdio ) ) ;
775
+ throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE' ,
776
+ 'stdio' , util . inspect ( stdio ) ) ;
774
777
}
775
778
776
779
// At least 3 stdio will be created
@@ -812,9 +815,9 @@ function _validateStdio(stdio, sync) {
812
815
// Cleanup previously created pipes
813
816
cleanup ( ) ;
814
817
if ( ! sync )
815
- throw new Error ( 'Child process can have only one IPC pipe ' ) ;
818
+ throw new errors . Error ( 'ERR_IPC_ONE_PIPE ' ) ;
816
819
else
817
- throw new Error ( 'You cannot use IPC with synchronous forks ' ) ;
820
+ throw new errors . Error ( 'ERR_IPC_SYNC_FORK ' ) ;
818
821
}
819
822
820
823
ipc = new Pipe ( true ) ;
@@ -849,15 +852,14 @@ function _validateStdio(stdio, sync) {
849
852
} else if ( isUint8Array ( stdio ) || typeof stdio === 'string' ) {
850
853
if ( ! sync ) {
851
854
cleanup ( ) ;
852
- throw new TypeError ( 'Asynchronous forks do not support ' +
853
- 'Buffer, Uint8Array or string input: ' +
854
- util . inspect ( stdio ) ) ;
855
+ throw new errors . TypeError ( 'ERR_INVALID_SYNC_FORK_INPUT' ,
856
+ util . inspect ( stdio ) ) ;
855
857
}
856
858
} else {
857
859
// Cleanup
858
860
cleanup ( ) ;
859
- throw new TypeError ( 'Incorrect value for stdio stream: ' +
860
- util . inspect ( stdio ) ) ;
861
+ throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE' , ' stdio' ,
862
+ util . inspect ( stdio ) ) ;
861
863
}
862
864
863
865
return acc ;
0 commit comments