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
Provenance
- Commit
bc0984e- Tree
11b84da- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
fd064a7
5 files changed+13 added−30 removed
modified:index.d.ts-9 removed
240 unmodified lines241 }242 243 interface ExecaSyncReturnValue<StdoutErrorType = string>244 extends ExecaReturnBase<StdoutErrorType> {245- /**246- The exit code of the process that was run.247- */248- code: number;245 }246 247 interface ExecaReturnValue<StdoutErrorType = string>248 extends ExecaSyncReturnValue<StdoutErrorType> {14 unmodified lines263 /**264 The error message.265 */266 message: string;271-272- /**273- The exit code (either numeric or textual) of the process that was run.274- */275- code: number | string;267 }268 269 interface ExecaError<StdoutErrorType = string>270 extends ExecaSyncError<StdoutErrorType> {103 unmodified linesmodified:index.js+5 added-6 removed
164 unmodified lines165 });166 }167 168 function 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;172 173 const [exitCodeName, exitCode] = getCode(result, code);174 175 const prefix = getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled});5 unmodified lines181 error = new Error(message);182 }183 184 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;190 191 if ('all' in result) {163 unmodified lines355 result.all = handleOutput(parsed.options, all);356 357 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 lines374 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 lines422 throw new TypeError('The `input` option cannot be a stream in sync mode');423 }424 425 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);428 429 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 lines446 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 linesmodified:index.test-d.ts-4 removed
12 unmodified lines1314151617171819206 unmodified lines2728293032313233347 unmodified lines4243444548464748496 unmodified lines56575859636061626385 unmodified lines12 unmodified lines execaPromise.cancel();
const unicornsResult = await execaPromise; expectType<string>(unicornsResult.command); expectType<string | number>(unicornsResult.code); expectType<number>(unicornsResult.exitCode); expectType<string>(unicornsResult.exitCodeName); expectType<string>(unicornsResult.stdout); expectType<string>(unicornsResult.stderr);6 unmodified lines} catch (error) { const execaError: ExecaError = error;
expectType<string>(execaError.message); expectType<number | string>(execaError.code); expectType<number>(execaError.exitCode); expectType<string>(execaError.exitCodeName); expectType<string>(execaError.stdout); expectType<string>(execaError.stderr);7 unmodified lines
try { const unicornsResult = execa.sync('unicorns'); expectType<string>(unicornsResult.command); expectType<string | number>(unicornsResult.code); expectType<number>(unicornsResult.exitCode); expectType<string>(unicornsResult.exitCodeName); expectType<string>(unicornsResult.stdout); expectType<string>(unicornsResult.stderr);6 unmodified lines} catch (error) { const execaError: ExecaSyncError = error;
expectType<string>(execaError.message); expectType<number | string>(execaError.code); expectType<number>(execaError.exitCode); expectType<string>(execaError.exitCodeName); expectType<string>(execaError.stdout); expectType<string>(execaError.stderr);85 unmodified linesmodified:readme.md-2 removed
60 unmodified lines61 /*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 lines100 /*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 linesmodified:test.js+8 added-9 removed
258 unmodified lines259 t.is(exitCodeName, 'Unknown system error -255');260 });261 262 test('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);267 269- 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 lines376 const error = await t.throwsAsync(execa('exit', [2]), {message: getExitRegExp('2')});377 t.is(error.signal, undefined);378 });379 381-async function code(t, num) {382- const error = await t.throwsAsync(execa('exit', [`${num}`]), {code: num, message: getExitRegExp(num)});383- t.is(error.exitCode, num);380+async function testExitCode(t, num) {381+ const {exitCode} = await t.throwsAsync(execa('exit', [`${num}`]), {message: getExitRegExp(num)});382+ t.is(exitCode, num);383 }384 386-test('error.code is 2', code, 2);387-test('error.code is 3', code, 3);388-test('error.code is 4', code, 4);385+test('error.exitCode is 2', testExitCode, 2);386+test('error.exitCode is 3', testExitCode, 3);387+test('error.exitCode is 4', testExitCode, 4);388 389 test('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