Skip to content

Commit

Permalink
child_process: better spawn error message
Browse files Browse the repository at this point in the history
Throw ERR_INVALID_ARG_VALUE when filename passed to spawn is empty.

Fixes: #19235

PR-URL: #19305
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
bzoz committed Mar 29, 2018
1 parent 852ba3a commit 9bfe55e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,12 @@ function _convertCustomFds(options) {
}

function normalizeSpawnArguments(file, args, options) {
if (typeof file !== 'string' || file.length === 0)
if (typeof file !== 'string')
throw new ERR_INVALID_ARG_TYPE('file', 'string', file);

if (file.length === 0)
throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty');

if (Array.isArray(args)) {
args = args.slice(0);
} else if (args !== undefined &&
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
const empty = fixtures.path('empty.js');

const invalidArgValueError =
common.expectsError({ code: 'ERR_INVALID_ARG_VALUE', type: TypeError }, 13);
common.expectsError({ code: 'ERR_INVALID_ARG_VALUE', type: TypeError }, 14);

const invalidArgTypeError =
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 11);
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 10);

assert.throws(function() {
const child = spawn(invalidcmd, 'this is not an array');
Expand All @@ -53,7 +53,7 @@ assert.throws(function() {

assert.throws(function() {
spawn('');
}, invalidArgTypeError);
}, invalidArgValueError);

assert.throws(function() {
const file = { toString() { return null; } };
Expand Down

0 comments on commit 9bfe55e

Please sign in to comment.