Skip to content

Commit

Permalink
wp-env: better run command errors (#22475)
Browse files Browse the repository at this point in the history
Fixes issues noticed in #21537 (comment).
  • Loading branch information
noahtallen authored May 19, 2020
1 parent 14da138 commit 6679219
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/env/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const withSpinner = ( command ) => ( ...args ) => {
spinner.fail( error.message );
process.exit( 1 );
} else if (
error &&
typeof error === 'object' &&
'exitCode' in error &&
'err' in error &&
'out' in error
Expand All @@ -54,13 +56,18 @@ const withSpinner = ( command ) => ( ...args ) => {
process.stderr.write( error.err );
}
process.exit( error.exitCode );
} else {
} else if ( error ) {
// Error is an unknown error. That means there was a bug in our code.
spinner.fail( error.message );
spinner.fail(
typeof error === 'string' ? error : error.message
);
// Disable reason: Using console.error() means we get a stack trace.
// eslint-disable-next-line no-console
console.error( error );
process.exit( 1 );
} else {
spinner.fail( 'An unknown error occured.' );
process.exit( 1 );
}
}
);
Expand Down
8 changes: 7 additions & 1 deletion packages/env/lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ module.exports = async function run( { container, command, spinner, debug } ) {
console.error(
process.stdout.isTTY ? `\n\n${ result.err }\n\n` : result.err
);
throw result.err;
// Some tools (like composer) may send messages to stderr. Those messages
// do not always mean that we need to abort the process. For example,
// composer will say "Nothing to install or update" on stderr when your
// local composer packages are up to date.
if ( result.exitCode !== 0 ) {
throw result.err;
}
}

spinner.text = `Ran \`${ command }\` in '${ container }'.`;
Expand Down

0 comments on commit 6679219

Please sign in to comment.