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

Improve error.killed #227

Merged
merged 2 commits into from May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = Boolean(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 @@ -362,6 +361,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