Skip to content

Commit 9bfe55e

Browse files
committed
child_process: better spawn error message
Throw ERR_INVALID_ARG_VALUE when filename passed to spawn is empty. Fixes: #19235 PR-URL: #19305 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 852ba3a commit 9bfe55e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/child_process.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,12 @@ function _convertCustomFds(options) {
386386
}
387387

388388
function normalizeSpawnArguments(file, args, options) {
389-
if (typeof file !== 'string' || file.length === 0)
389+
if (typeof file !== 'string')
390390
throw new ERR_INVALID_ARG_TYPE('file', 'string', file);
391391

392+
if (file.length === 0)
393+
throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty');
394+
392395
if (Array.isArray(args)) {
393396
args = args.slice(0);
394397
} else if (args !== undefined &&

test/parallel/test-child-process-spawn-typeerror.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
3030
const empty = fixtures.path('empty.js');
3131

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

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

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

5454
assert.throws(function() {
5555
spawn('');
56-
}, invalidArgTypeError);
56+
}, invalidArgValueError);
5757

5858
assert.throws(function() {
5959
const file = { toString() { return null; } };

0 commit comments

Comments
 (0)