Skip to content

Commit

Permalink
Make stdout and stderr empty strings with execa.sync() on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 14, 2019
1 parent c7d42b7 commit ace8ef2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Expand Up @@ -109,9 +109,10 @@ function handleInput(spawned, input) {
}
}

function handleOutput(options, value) {
function handleOutput(options, value, error) {
if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
return;
// When `execa.sync()` errors, we normalize it to '' to mimic `execa()`
return error === undefined ? undefined : '';
}

if (options.stripFinalNewline) {
Expand Down Expand Up @@ -427,8 +428,8 @@ module.exports.sync = (command, args, options) => {
}

const result = childProcess.spawnSync(parsed.command, parsed.args, parsed.options);
result.stdout = handleOutput(parsed.options, result.stdout);
result.stderr = handleOutput(parsed.options, result.stderr);
result.stdout = handleOutput(parsed.options, result.stdout, result.error);
result.stderr = handleOutput(parsed.options, result.stderr, result.error);

if (result.error || result.status !== 0 || result.signal !== null) {
const error = makeError(result, {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Expand Up @@ -107,6 +107,8 @@ try {
command: 'wrong command',
exitCode: 2,
exitCodeName: 'ENOENT',
stdout: '',
stderr: '',
failed: true,
timedOut: false,
isCanceled: false,
Expand Down

0 comments on commit ace8ef2

Please sign in to comment.