diff --git a/index.js b/index.js index a3cc846a75..46f18da2de 100644 --- a/index.js +++ b/index.js @@ -173,7 +173,7 @@ function getStream(process, stream, {encoding, buffer, maxBuffer}) { function makeError(result, options) { const {stdout, stderr, code, signal} = result; let {error} = result; - const {joinedCommand, timedOut, isCanceled, parsed: {options: {timeout}}} = options; + const {joinedCommand, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options; const [exitCodeName, exitCode] = getCode(result, code); @@ -194,10 +194,10 @@ function makeError(result, options) { // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize // it to `undefined` error.signal = signal || undefined; - error.killed = signal !== null && !timedOut; error.command = joinedCommand; error.timedOut = Boolean(timedOut); error.isCanceled = isCanceled; + error.killed = killed && !timedOut; if ('all' in result) { error.all = result.all; @@ -364,7 +364,8 @@ const execa = (command, args, options) => { joinedCommand, parsed, timedOut, - isCanceled + isCanceled, + killed: spawned.killed }); if (!parsed.options.reject) { diff --git a/test.js b/test.js index 7a8919d807..478b2508b9 100644 --- a/test.js +++ b/test.js @@ -330,7 +330,7 @@ test('error.killed is true if process was killed directly', async t => { t.true(error.killed); }); -test('error.killed is true if process was killed indirectly', async t => { +test('error.killed is false if process was killed indirectly', async t => { const cp = execa('forever'); setTimeout(() => { @@ -340,7 +340,7 @@ test('error.killed is true if process was killed indirectly', async t => { // `process.kill()` is emulated by Node.js on Windows const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/; const error = await t.throwsAsync(cp, {message}); - t.true(error.killed); + t.false(error.killed); }); if (process.platform === 'darwin') {