From 1f427fd71a515377a19640a3fc8a7e7a9f9b746d Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 18:58:38 +0200 Subject: [PATCH] Remove `error.code` --- index.js | 4 +--- readme.md | 2 -- test.js | 17 ++++++++--------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 303537d957..cf97b6e82c 100644 --- a/index.js +++ b/index.js @@ -182,9 +182,9 @@ function makeError(result, options) { } error.command = joinedCommand; + delete error.code; error.exitCode = exitCode; error.exitCodeName = exitCodeName; - error.code = exitCode || exitCodeName; error.stdout = stdout; error.stderr = stderr; @@ -374,7 +374,6 @@ const execa = (command, args, options) => { command: joinedCommand, exitCode: 0, exitCodeName: 'SUCCESS', - code: 0, stdout: result.stdout, stderr: result.stderr, all: result.all, @@ -446,7 +445,6 @@ module.exports.sync = (command, args, options) => { command: joinedCommand, exitCode: 0, exitCodeName: 'SUCCESS', - code: 0, stdout: result.stdout, stderr: result.stderr, failed: false, diff --git a/readme.md b/readme.md index d735f01431..c851467e21 100644 --- a/readme.md +++ b/readme.md @@ -62,7 +62,6 @@ const execa = require('execa'); { message: 'Command failed with exit code 2 (ENOENT): wrong command spawn wrong ENOENT', errno: 'ENOENT', - code: 2, syscall: 'spawn wrong', path: 'wrong', spawnargs: ['command'], @@ -102,7 +101,6 @@ try { { message: 'Command failed with exit code 2 (ENOENT): wrong command spawnSync wrong ENOENT', errno: 'ENOENT', - code: 2, syscall: 'spawnSync wrong', path: 'wrong', spawnargs: ['command'], diff --git a/test.js b/test.js index 9579764332..fd5b87e6c2 100644 --- a/test.js +++ b/test.js @@ -258,13 +258,12 @@ test('allow unknown exit code', async t => { }); test('execa() returns code and failed properties', async t => { - const {code, exitCode, exitCodeName, failed} = await execa('noop', ['foo']); - t.is(code, 0); + const {exitCode, exitCodeName, failed} = await execa('noop', ['foo']); t.is(exitCode, 0); t.is(exitCodeName, 'SUCCESS'); t.false(failed); - const error = await t.throwsAsync(execa('exit', ['2']), {code: 2, message: getExitRegExp('2')}); + const error = await t.throwsAsync(execa('exit', ['2']), {message: getExitRegExp('2')}); t.is(error.exitCode, 2); const expectedName = process.platform === 'win32' ? 'Unknown system error -2' : 'ENOENT'; t.is(error.exitCodeName, expectedName); @@ -364,14 +363,14 @@ test('result.signal is undefined if process failed, but was not killed', async t t.is(error.signal, undefined); }); -async function code(t, num) { - const error = await t.throwsAsync(execa('exit', [`${num}`]), {code: num, message: getExitRegExp(num)}); - t.is(error.exitCode, num); +async function testExitCode(t, num) { + const {exitCode} = await t.throwsAsync(execa('exit', [`${num}`]), {message: getExitRegExp(num)}); + t.is(exitCode, num); } -test('error.code is 2', code, 2); -test('error.code is 3', code, 3); -test('error.code is 4', code, 4); +test('error.exitCode is 2', testExitCode, 2); +test('error.exitCode is 3', testExitCode, 3); +test('error.exitCode is 4', testExitCode, 4); test('timeout kills the process if it times out', async t => { const error = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));