-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wp-env: no longer show error message twice #20157
Conversation
The spinner is for single line errors.
The log should be reserved for standard error output.
In other words, always do the spinner thing and only log if the out
property is present.
|
Makes sense! Done :) |
Looks good to me but I’ll let @noisysocks approve as he was the last one to
touch this.
|
44f5e3c
to
400f22b
Compare
Rebased. cc @noisysocks again just in case. ;) |
I think we still want to print This part of the code confused me too. There's many types of error and so writing one handler for them all involves considering several execution paths 😅 I'm thinking let's give up and just explicitly handle each of the different error types instead: ( error ) => {
if ( error instanceof env.ValidationError ) {
// Error is a validation error. That means the user did something wrong.
spinner.fail( error.message );
process.exit( 1 );
} else if (
'exitCode' in error &&
'err' in error &&
'out' in error
) {
// Error is a docker-compose error. That means something docker-related failed.
// https://github.com/PDMLab/docker-compose/blob/master/src/index.ts
spinner.fail( 'Error while running docker-compose command.' );
if ( error.out ) {
process.stdout.write( error.out );
}
if ( error.err ) {
process.stderr.write( error.err );
}
process.exit( error.exitCode );
} else {
// Error is an unknown error. That means there was a bug in our code.
spinner.fail( 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 );
}
} |
- Separate cases for errors we know about - More straightforward general error case
400f22b
to
aaafd07
Compare
@noisysocks That makes a lot of sense, done! ✅ Updated with the new code, the same error looks like this, which is definitely an improvement. |
* Handle errors more robustly - Separate cases for errors we know about - More straightforward general error case * Update tests to handle the new error format
* Handle errors more robustly - Separate cases for errors we know about - More straightforward general error case * Update tests to handle the new error format
I noticed during some testing today that wp-env would show error messages twice. This PR attempts to only display the error message once. @noisysocks / @epiqueras I may be missing the context for why we needed to check for
error instanceof env.ValidationError
and then display the error twice, so if you have thoughts I'm all ears. :) Perhaps there are some cases where multiline error output wouldn't be shown byspinner.fail
?Screenshots
Checklist: