From ae987cb95bd7e15db625c440a579d99a03a41e57 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Mon, 12 Mar 2018 22:41:19 +0100 Subject: [PATCH] child_process: better spawn error message Throw ERR_INVALID_ARG_VALUE when filename passed to spawn is empty. Fixes: https://github.com/nodejs/node/issues/19235 --- lib/child_process.js | 5 ++++- test/parallel/test-child-process-spawn-typeerror.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index c18329554a46b9..2c68e4c209d07f 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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 && diff --git a/test/parallel/test-child-process-spawn-typeerror.js b/test/parallel/test-child-process-spawn-typeerror.js index 2a2c1de277cc1b..791cf02280a3cb 100644 --- a/test/parallel/test-child-process-spawn-typeerror.js +++ b/test/parallel/test-child-process-spawn-typeerror.js @@ -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'); @@ -53,7 +53,7 @@ assert.throws(function() { assert.throws(function() { spawn(''); -}, invalidArgTypeError); +}, invalidArgValueError); assert.throws(function() { const file = { toString() { return null; } };