@@ -8,6 +8,7 @@ const dgram = require('dgram');
88const util = require ( 'util' ) ;
99const constants = process . binding ( 'constants' ) . os . signals ;
1010const assert = require ( 'assert' ) ;
11+ const errors = require ( 'internal/errors' ) ;
1112
1213const Process = process . binding ( 'process_wrap' ) . Process ;
1314const WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
@@ -372,7 +373,7 @@ ChildProcess.prototype.kill = function(sig) {
372373 }
373374
374375 if ( signal === undefined ) {
375- throw new Error ( 'Unknown signal: ' + sig ) ;
376+ throw new errors . Error ( 'INVALID_SIGNAL' , sig ) ;
376377 }
377378
378379 if ( this . _handle ) {
@@ -537,7 +538,7 @@ function setupChannel(target, channel) {
537538 if ( this . connected ) {
538539 return this . _send ( message , handle , options , callback ) ;
539540 }
540- const ex = new Error ( 'channel closed ' ) ;
541+ const ex = new errors . Error ( 'CHANNEL_CLOSED ' ) ;
541542 if ( typeof callback === 'function' ) {
542543 process . nextTick ( callback , ex ) ;
543544 } else {
@@ -577,7 +578,7 @@ function setupChannel(target, channel) {
577578 } else if ( handle instanceof UDP ) {
578579 message . type = 'dgram.Native' ;
579580 } else {
580- throw new TypeError ( 'This handle type can\'t be sent ' ) ;
581+ throw new errors . TypeError ( 'INVALID_HANDLE_TYPE ' ) ;
581582 }
582583
583584 // Queue-up message and handle if we haven't received ACK yet.
@@ -677,7 +678,7 @@ function setupChannel(target, channel) {
677678
678679 target . disconnect = function ( ) {
679680 if ( ! this . connected ) {
680- this . emit ( 'error' , new Error ( 'IPC channel is already disconnected ' ) ) ;
681+ this . emit ( 'error' , new errors . Error ( 'CHILD_PROCESS_IPC_DISCONNECTED ' ) ) ;
681682 return ;
682683 }
683684
@@ -757,11 +758,11 @@ function _validateStdio(stdio, sync) {
757758 case 'ignore' : stdio = [ 'ignore' , 'ignore' , 'ignore' ] ; break ;
758759 case 'pipe' : stdio = [ 'pipe' , 'pipe' , 'pipe' ] ; break ;
759760 case 'inherit' : stdio = [ 0 , 1 , 2 ] ; break ;
760- default : throw new TypeError ( 'Incorrect value of stdio option: ' + stdio ) ;
761+ default : throw new errors . TypeError ( 'CHILD_PROCESS_INVALID_STDIO' , stdio ) ;
761762 }
762763 } else if ( ! Array . isArray ( stdio ) ) {
763- throw new TypeError ( 'Incorrect value of stdio option: ' +
764- util . inspect ( stdio ) ) ;
764+ throw new errors . TypeError ( 'CHILD_PROCESS_INVALID_STDIO' ,
765+ util . inspect ( stdio ) ) ;
765766 }
766767
767768 // At least 3 stdio will be created
@@ -805,9 +806,9 @@ function _validateStdio(stdio, sync) {
805806 // Cleanup previously created pipes
806807 cleanup ( ) ;
807808 if ( ! sync )
808- throw new Error ( 'Child process can have only one IPC pipe ' ) ;
809+ throw new errors . Error ( 'CHILD_PROCESS_ONE_IPC ' ) ;
809810 else
810- throw new Error ( 'You cannot use IPC with synchronous forks ' ) ;
811+ throw new errors . Error ( 'CHILD_PROCESS_SYNCHRONOUS_FORK_NO_IPC ' ) ;
811812 }
812813
813814 ipc = new Pipe ( true ) ;
@@ -842,14 +843,14 @@ function _validateStdio(stdio, sync) {
842843 } else if ( stdio instanceof Buffer || typeof stdio === 'string' ) {
843844 if ( ! sync ) {
844845 cleanup ( ) ;
845- throw new TypeError ( 'Asynchronous forks do not support Buffer input: ' +
846- util . inspect ( stdio ) ) ;
846+ throw new errors . TypeError ( 'CHILD_PROCESS_ASYNC_NO_BUFFER' ,
847+ util . inspect ( stdio ) ) ;
847848 }
848849 } else {
849850 // Cleanup
850851 cleanup ( ) ;
851- throw new TypeError ( 'Incorrect value for stdio stream: ' +
852- util . inspect ( stdio ) ) ;
852+ throw new errors . TypeError ( 'CHILD_PROCESS_INVALID_STDIO' ,
853+ util . inspect ( stdio ) ) ;
853854 }
854855
855856 return acc ;
0 commit comments