Propagate exceptions from parallel
where possible
#2095
Merged
+201
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the original implementation of our prettier runtime errors (#1320), we wrapped the errors thrown within
parallel
functions into an exception object. This means the call-stack is available to the catching-code, and so is able to report a pretty exception message.Unfortunately, this was a breaking change, and so we had to roll that back. Some people were
pcall
ing the parallel function, and matching on the result of the error. For example:This is a second attempt at this, using a technique I've affectionately dubbed "magic throws". The
parallel
API is now aware of whether it is beingpcall
ed or not, and thus able to decide whether to wrap the error into an exception or not:I think there are some risks with this approach. It's not obvious to users whether you'll get the fancy error reporting or not, and that could be confusing — the "magic" in "magic throws" is not a necessarily a good thing!
I still think this change is worth merging (we can always revert it if it proves to be a mistake), but definitely open to feedback.
I'd quite like to extend this to approach to other bits of the code — we could do something similar to provide better error messages for
require
.