Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: better spawn error message #19305

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,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