Skip to content
Myr

Add `error.signalDescription` (#378)

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 1ac56ea · Browse files · 6 files+47 added−5 removed
This commit

State

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

Diff stats

6 files+47 added−5 removed

  • tests:+14 added−0 removed
  • other:+33 added−5 removed

6 files+47 added−5 removed

modified:lib/error.js+7 added-3 removed
modified:test/error.js+14 added
131 unmodified lines
132 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});133 t.is(signal, 'SIGINT');134 });135136 test('error.signalDescription is defined', async t => {137 const subprocess = execa('noop');138139 process.kill(subprocess.pid, 'SIGINT');140141 const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});142 t.is(signalDescription, 'User interruption with CTRL-C');143 });144145 test('error.signal is SIGTERM', async t => {146 const subprocess = execa('noop');147148 process.kill(subprocess.pid, 'SIGTERM');
26 unmodified lines
175 const {signal} = await t.throwsAsync(execa('exit', [2]), {message: getExitRegExp('2')});176 t.is(signal, undefined);177});178179test('result.signalDescription is undefined for successful execution', async t => {180 const {signalDescription} = await execa('noop');181 t.is(signalDescription, undefined);182});183184test('error.code is undefined on success', async t => {185 const {code} = await execa('noop');186 t.is(code, undefined);187});
5 unmodified lines
modified:index.d.ts+10 added-1 removed
265 unmodified lines
266 */267 killed: boolean;268269 /**270 The signal that was used to terminate the process.270 The name of the signal that was used to terminate the process. For example, `SIGFPE`.271272 If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`.273 */274 signal?: string;275276 /**277 A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.278279 If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.280 */281 signalDescription?: string;282 }283284 interface ExecaSyncReturnValue<StdoutErrorType = string>285 extends ExecaReturnBase<StdoutErrorType> {
237 unmodified lines
modified:index.test-d.ts+4 added
23 unmodified lines
24 expectType<boolean>(unicornsResult.timedOut);25 expectType<boolean>(unicornsResult.isCanceled);26 expectType<boolean>(unicornsResult.killed);27 expectType<string | undefined>(unicornsResult.signal);28 expectType<string | undefined>(unicornsResult.signalDescription);29} catch (error) {30 const execaError: ExecaError = error;3132 expectType<string>(execaError.message);
5 unmodified lines
38 expectType<boolean>(execaError.timedOut);39 expectType<boolean>(execaError.isCanceled);40 expectType<boolean>(execaError.killed);41 expectType<string | undefined>(execaError.signal);42 expectType<string | undefined>(execaError.signalDescription);43 expectType<string | undefined>(execaError.originalMessage);44}4546try {
7 unmodified lines
54 expectType<boolean>(unicornsResult.timedOut);55 expectError(unicornsResult.isCanceled);56 expectType<boolean>(unicornsResult.killed);57 expectType<string | undefined>(unicornsResult.signal);58 expectType<string | undefined>(unicornsResult.signalDescription);59} catch (error) {60 const execaError: ExecaSyncError = error;6162 expectType<string>(execaError.message);
5 unmodified lines
68 expectType<boolean>(execaError.timedOut);69 expectError(execaError.isCanceled);70 expectType<boolean>(execaError.killed);71 expectType<string | undefined>(execaError.signal);72 expectType<string | undefined>(execaError.signalDescription);73 expectType<string | undefined>(execaError.originalMessage);74}7576execa('unicorns', {cleanup: false});
111 unmodified lines
modified:package.json+1 added
modified:readme.md+11 added-1 removed
268 unmodified lines
269#### signal270271Type: `string | undefined`272273The signal that was used to terminate the process.273The name of the signal that was used to terminate the process. For example, `SIGFPE`.274275If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`.276277#### signalDescription278279Type: `string | undefined`280281A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.282283If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.284285#### originalMessage286287Type: `string | undefined`288
289 unmodified lines