Skip to content

Commit

Permalink
Improve error.killed (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed May 10, 2019
1 parent bb36e6d commit b5dfb0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions index.js
Expand Up @@ -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);

Expand All @@ -198,6 +198,7 @@ function makeError(result, options) {
error.command = joinedCommand;
error.timedOut = timedOut;
error.isCanceled = isCanceled;
error.killed = killed && !timedOut;

if ('all' in result) {
error.all = result.all;
Expand Down Expand Up @@ -364,14 +365,10 @@ const execa = (command, args, options) => {
joinedCommand,
parsed,
timedOut,
isCanceled
isCanceled,
killed: spawned.killed
});

// TODO: missing some timeout logic for killed
// https://github.com/nodejs/node/blob/master/lib/child_process.js#L203
// error.killed = spawned.killed || killed;
error.killed = error.killed || spawned.killed;

if (!parsed.options.reject) {
return error;
}
Expand Down
2 changes: 1 addition & 1 deletion test.js
Expand Up @@ -293,7 +293,6 @@ test('error.killed is true if process was killed directly', async t => {
t.true(error.killed);
});

// TODO: Should this really be the case, or should we improve on child_process?
test('error.killed is false if process was killed indirectly', async t => {
const cp = execa('forever');

Expand Down Expand Up @@ -372,6 +371,7 @@ test('error.code is 4', code, 4);

test('timeout kills the process if it times out', async t => {
const error = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));
t.false(error.killed);
t.true(error.timedOut);
});

Expand Down

0 comments on commit b5dfb0b

Please sign in to comment.