Skip to content
Myr

Improve `error.killed` (#227)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent bb36e6d · Browse files · 2 files+5 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−8 removed

  • other:+5 added−8 removed

2 files+5 added−8 removed

modified:index.js+4 added-7 removed
171 unmodified lines
172173function makeError(result, options) {174 const {stdout, stderr, code, signal} = result;175 let {error} = result;176 const {joinedCommand, timedOut, isCanceled, parsed: {options: {timeout}}} = options;176 const {joinedCommand, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options;177178 const [exitCodeName, exitCode] = getCode(result, code);179180 const prefix = getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled});
16 unmodified lines
197 error.signal = signal || undefined;198 error.command = joinedCommand;199 error.timedOut = timedOut;200 error.isCanceled = isCanceled;201 error.killed = killed && !timedOut;202203 if ('all' in result) {204 error.all = result.all;205 }
158 unmodified lines
364 const error = makeError(result, {365 joinedCommand,366 parsed,367 timedOut,367 isCanceled368 isCanceled,369 killed: spawned.killed370 });371370 // TODO: missing some timeout logic for killed371 // https://github.com/nodejs/node/blob/master/lib/child_process.js#L203372 // error.killed = spawned.killed || killed;373 error.killed = error.killed || spawned.killed;374372 if (!parsed.options.reject) {373 return error;374 }375
98 unmodified lines
modified:test.js+1 added-1 removed
291 unmodified lines
292 const error = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});293 t.true(error.killed);294});295296// TODO: Should this really be the case, or should we improve on child_process?296test('error.killed is false if process was killed indirectly', async t => {297 const cp = execa('forever');298299 process.kill(cp.pid, 'SIGINT');
70 unmodified lines
370test('error.code is 4', code, 4);371372test('timeout kills the process if it times out', async t => {373 const error = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));374 t.false(error.killed);375 t.true(error.timedOut);376});377378test('timeout does not kill the process if it does not time out', async t => {
279 unmodified lines