Skip to content
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

Merged
merged 2 commits into from
Feb 13, 2020
Merged

Conversation

noahtallen
Copy link
Member

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 by spinner.fail?

Screenshots

Screen Shot 2020-02-10 at 2 21 57 PM

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@noahtallen noahtallen added [Type] Bug An existing feature does not function as intended [Tool] Env /packages/env labels Feb 10, 2020
@noahtallen noahtallen self-assigned this Feb 10, 2020
@epiqueras
Copy link
Contributor

epiqueras commented Feb 10, 2020 via email

@noahtallen
Copy link
Member Author

Makes sense! Done :)

@epiqueras
Copy link
Contributor

epiqueras commented Feb 10, 2020 via email

@noahtallen
Copy link
Member Author

Rebased. cc @noisysocks again just in case. ;)

@noisysocks
Copy link
Member

I think we still want to print error.err to STDERR?

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
@noahtallen noahtallen force-pushed the fix/wp-env-errors-twice branch from 400f22b to aaafd07 Compare February 13, 2020 03:12
@noahtallen
Copy link
Member Author

@noisysocks That makes a lot of sense, done! ✅

Updated with the new code, the same error looks like this, which is definitely an improvement.

Screen Shot 2020-02-12 at 7 14 39 PM

@noisysocks noisysocks merged commit 7891953 into master Feb 13, 2020
@noisysocks noisysocks deleted the fix/wp-env-errors-twice branch February 13, 2020 04:08
@github-actions github-actions bot added this to the Gutenberg 7.6 milestone Feb 13, 2020
@jorgefilipecosta jorgefilipecosta added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Mar 2, 2020
jorgefilipecosta pushed a commit that referenced this pull request Mar 2, 2020
* Handle errors more robustly

- Separate cases for errors we know about
- More straightforward general error case

* Update tests to handle the new error format
jorgefilipecosta pushed a commit that referenced this pull request Mar 2, 2020
* Handle errors more robustly

- Separate cases for errors we know about
- More straightforward general error case

* Update tests to handle the new error format
@jorgefilipecosta jorgefilipecosta removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] Env /packages/env [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants