Skip to content
Myr

Remove `error.code` (#250)

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 fd064a7 · Browse files · 5 files+13 added−30 removed
This commit

State

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

Diff stats

5 files+13 added−30 removed

  • other:+13 added−30 removed

5 files+13 added−30 removed

modified:index.d.ts-9 removed
240 unmodified lines
241 }242243 interface ExecaSyncReturnValue<StdoutErrorType = string>244 extends ExecaReturnBase<StdoutErrorType> {245 /**246 The exit code of the process that was run.247 */248 code: number;245 }246247 interface ExecaReturnValue<StdoutErrorType = string>248 extends ExecaSyncReturnValue<StdoutErrorType> {
14 unmodified lines
263 /**264 The error message.265 */266 message: string;271272 /**273 The exit code (either numeric or textual) of the process that was run.274 */275 code: number | string;267 }268269 interface ExecaError<StdoutErrorType = string>270 extends ExecaSyncError<StdoutErrorType> {
103 unmodified lines
modified:index.js+5 added-6 removed
164 unmodified lines
165 });166}167168function makeError(result, options) {169 const {stdout, stderr, code, signal} = result;169 const {stdout, stderr, signal} = result;170 let {error} = result;171 const {joinedCommand, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options;171 const {code, joinedCommand, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options;172173 const [exitCodeName, exitCode] = getCode(result, code);174175 const prefix = getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled});
5 unmodified lines
181 error = new Error(message);182 }183184 error.command = joinedCommand;185 delete error.code;186 error.exitCode = exitCode;187 error.exitCodeName = exitCodeName;187 error.code = exitCode || exitCodeName;188 error.stdout = stdout;189 error.stderr = stderr;190191 if ('all' in result) {
163 unmodified lines
355 result.all = handleOutput(parsed.options, all);356357 if (result.error || result.code !== 0 || result.signal !== null) {358 const error = makeError(result, {359 code: result.code,360 joinedCommand,361 parsed,362 timedOut,363 isCanceled,
10 unmodified lines
374 return {375 command: joinedCommand,376 exitCode: 0,377 exitCodeName: 'SUCCESS',377 code: 0,378 stdout: result.stdout,379 stderr: result.stderr,380 all: result.all,381 failed: false,
40 unmodified lines
422 throw new TypeError('The `input` option cannot be a stream in sync mode');423 }424425 const result = childProcess.spawnSync(parsed.command, parsed.args, parsed.options);426 result.code = result.status;426 result.stdout = handleOutput(parsed.options, result.stdout);427 result.stderr = handleOutput(parsed.options, result.stderr);428429 if (result.error || result.status !== 0 || result.signal !== null) {430 const error = makeError(result, {431 code: result.status,432 joinedCommand,433 parsed,434 timedOut: false,435 isCanceled: false,
10 unmodified lines
446 return {447 command: joinedCommand,448 exitCode: 0,449 exitCodeName: 'SUCCESS',450 code: 0,450 stdout: result.stdout,451 stderr: result.stderr,452 failed: false,453 timedOut: false,
4 unmodified lines
modified:index.test-d.ts-4 removed
modified:readme.md-2 removed
60 unmodified lines
61 /*62 {63 message: 'Command failed with exit code 2 (ENOENT): wrong command spawn wrong ENOENT',64 errno: 'ENOENT',65 code: 2,65 syscall: 'spawn wrong',66 path: 'wrong',67 spawnargs: ['command'],68 command: 'wrong command',
31 unmodified lines
100 /*101 {102 message: 'Command failed with exit code 2 (ENOENT): wrong command spawnSync wrong ENOENT',103 errno: 'ENOENT',105 code: 2,104 syscall: 'spawnSync wrong',105 path: 'wrong',106 spawnargs: ['command'],107 command: 'wrong command',
321 unmodified lines
modified:test.js+8 added-9 removed
258 unmodified lines
259 t.is(exitCodeName, 'Unknown system error -255');260});261262test('execa() returns code and failed properties', async t => {263 const {code, exitCode, exitCodeName, failed} = await execa('noop', ['foo']);264 t.is(code, 0);263 const {exitCode, exitCodeName, failed} = await execa('noop', ['foo']);264 t.is(exitCode, 0);265 t.is(exitCodeName, 'SUCCESS');266 t.false(failed);267269 const error = await t.throwsAsync(execa('exit', ['2']), {code: 2, message: getExitRegExp('2')});268 const error = await t.throwsAsync(execa('exit', ['2']), {message: getExitRegExp('2')});269 t.is(error.exitCode, 2);270 const expectedName = process.platform === 'win32' ? 'Unknown system error -2' : 'ENOENT';271 t.is(error.exitCodeName, expectedName);272 t.true(error.failed);
103 unmodified lines
376 const error = await t.throwsAsync(execa('exit', [2]), {message: getExitRegExp('2')});377 t.is(error.signal, undefined);378});379381async function code(t, num) {382 const error = await t.throwsAsync(execa('exit', [`${num}`]), {code: num, message: getExitRegExp(num)});383 t.is(error.exitCode, num);380async function testExitCode(t, num) {381 const {exitCode} = await t.throwsAsync(execa('exit', [`${num}`]), {message: getExitRegExp(num)});382 t.is(exitCode, num);383}384386test('error.code is 2', code, 2);387test('error.code is 3', code, 3);388test('error.code is 4', code, 4);385test('error.exitCode is 2', testExitCode, 2);386test('error.exitCode is 3', testExitCode, 3);387test('error.exitCode is 4', testExitCode, 4);388389test('timeout kills the process if it times out', async t => {390 const error = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));391 t.false(error.killed);
285 unmodified lines