Skip to content

Commit

Permalink
Remove error.code
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 14, 2019
1 parent 1f9ca1e commit b77e9ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 1 addition & 3 deletions index.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions readme.md
Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down
17 changes: 8 additions & 9 deletions test.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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}));
Expand Down

0 comments on commit b77e9ff

Please sign in to comment.