Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: handle env and stage errors cleanly. Closes #1942 #1943

Merged
merged 7 commits into from
Nov 7, 2019

Conversation

zetlen
Copy link
Contributor

@zetlen zetlen commented Oct 29, 2019

Description

  • Add error checks for all usages of loadEnvironment()
  • Add better error handling for Buildpack CLI and venia-concept staging server

Related Issue

Closes #1942.

Acceptance

Verification Stakeholders

@dpatil-magento

Verification Steps

Verify that #1942 is no longer reproducible when the environment is invalid.

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@zetlen zetlen added tooling Related to the developer tooling, including buildpack, webpack plugins, and debug UIs. pkg:pwa-buildpack labels Oct 29, 2019
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Oct 29, 2019

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

Generated by 🚫 dangerJS against 1db0b5e

@zetlen zetlen added the version: Patch This changeset includes backwards compatible bug fixes. label Oct 30, 2019
@zetlen zetlen force-pushed the zetlen/fix-loadenv-1942 branch from 6d590d1 to 31e6200 Compare October 30, 2019 21:10
@@ -29,7 +29,7 @@
"storybook:build": "yarn run storybook",
"test": "yarn run -s prettier:check && yarn run -s lint && jest",
"validate-queries": "yarn run download-schema && graphql validate-magento-pwa-queries --project venia",
"watch": "webpack-dev-server --progress --color --env.mode development"
"watch": "buildpack load-env . && webpack-dev-server --progress --color --env.mode development"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key here, right? We now validate the environment before running the dev server. We should add this to start:debug and to the watch:all script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it belongs in start:debug, but it definitely belongs in watch:all. Good looking out.

@@ -11,6 +11,11 @@ const path = require('path');
async function serve() {
const config = loadEnvironment(__dirname);

if (config.error) {
// loadEnvironment takes care of logging it
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test this I had to do:

❯ DEV_SERVER_PORT=bad yarn run stage:venia

Just FYI for other verifiers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, I didn't copy the verification steps over from #1942.

throw err;
}
const error = err || msg;
prettyLogger.error(error.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I test this? I commented out this code and nothing happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fallback error handler for an unrecognized command. If you comment it out and run buildpack with no arguments, you'll see the difference. It belongs in this ticket because it's about handling errors cleanly, and this fallback error handler will handle all errors in upcoming versions of yargs.

fix: watch:all and handler comment
@zetlen zetlen force-pushed the zetlen/fix-loadenv-1942 branch from 282a44a to fe2bc57 Compare October 31, 2019 17:14
@zetlen zetlen requested a review from sirugh October 31, 2019 17:14
sirugh
sirugh previously approved these changes Nov 4, 2019
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did make changes! Thanks :)

jimbo
jimbo previously approved these changes Nov 4, 2019
@dpatil-magento
Copy link
Contributor

@zetlen bash docker/run-docker failing.

Works on develop :
image

Erron on zetlen/fix-loadenv-1942 :
image

@zetlen zetlen dismissed stale reviews from jimbo and sirugh via da5cd9e November 5, 2019 21:02
@dpatil-magento
Copy link
Contributor

QA Pass, @sirugh and/or @jimbo Can be merged once you approve latest commit.

package.json Outdated
@@ -31,6 +31,7 @@
"prepare": "node scripts/monorepo-introduction.js",
"prettier": "prettier --loglevel warn --write '@(packages|scripts)/**/*.@(css|graphql|js)' '*.js'",
"prettier:check": "prettier --list-different '@(packages|scripts)/**/*.@(css|graphql|js)' '*.js'",
"prevenia": "node ./packages/pwa-buildpack/bin/buildpack load-env ./packages/venia-concept",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is prevenia?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It runs before yarn run venia. I'm just using the NPM scripts pre feature here to make the code a little easier to read. But I guess it didn't work on you. Should I just put this in venia instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. So since venia is just shorthand for yarn workspace @magento/venia-concept, this script runs every time yarn venia is invoked.

This is clever, but it may result in some surprising outcomes. If someone doesn't know about your venia shorthand, and tries to do a standard thing such as yarn workspace @magento/venia-concept run validate-queries, they'll miss out on load-env and probably be confused about why it's not working.

At least if all of that is in venia, they'll immediately see what the problem was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. The rest of our scripts are littered with shell &&s, so that's what this will be too.

@dpatil-magento
Copy link
Contributor

re-verified after recent commits, looks good.

@dpatil-magento dpatil-magento merged commit 8ff974d into develop Nov 7, 2019
@dpatil-magento dpatil-magento deleted the zetlen/fix-loadenv-1942 branch September 14, 2020 22:02
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
pkg:pwa-buildpack pkg:venia-concept tooling Related to the developer tooling, including buildpack, webpack plugins, and debug UIs. version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: Build and watch fail with bad error message when environment validation fails
5 participants