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

chore(build): properly handle worker errors #2434

Merged
merged 2 commits into from
Aug 12, 2021
Merged

Conversation

nolanlawson
Copy link
Contributor

Details

In the lwc package, in the build.js script, if any of the worker processes throws an error, currently it will just hang forever with no output. This can be confusing. 🙂

This PR fixes it so that if any worker throws an error, the process exits with a non-zero exit code and logs the error. I confirmed that this worked by throwing a deliberate Error in one of the build workers and confirming that it gave useful error output.

Does this PR introduce breaking changes?

  • No, it does not introduce breaking changes.

targets.forEach((config) => {
workers(config, (err) => {
if (err) {
return reject(err);
console.error(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

would this error be displayed 2 times? (here and in in the catch )
What happens when there are multiple errors? e.g. multiple targets generate errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think it would be displayed two times. I figured it was easiest to just log all the exceptions, since as you say there could be multiple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case of multiple exceptions we print them all but then reject with the last one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I figured. wouldn't be better to reject with an array of exceptions and print them all, only once in the catch?

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 thought it was bad practice to reject with anything but an Error? But I guess if we're the only ones handling it, then it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I came up with a much simpler solution using Promise.all and promisify. No need to do any fancy error handling ourselves; just let Promise.all handle it.

Copy link
Contributor

@jodarove jodarove left a comment

Choose a reason for hiding this comment

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

lgtm

@nolanlawson nolanlawson merged commit 8131e9e into master Aug 12, 2021
@nolanlawson nolanlawson deleted the nolan/worker-errors branch August 12, 2021 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants