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.
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
Error handling improvements to esbuild plugin #2595
Error handling improvements to esbuild plugin #2595
Changes from 9 commits
3d2e68e
d3d13e1
199439e
ed891fc
377c6e4
0b85289
bbe4f87
2b32e26
3dffdcf
a89028b
d3c901f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these lines because otherwise the “cause” is lost? That ESBuild doesn’t print them?
Is that something that ESbuild should fix? Upstream?
Or, if indeed needed here, perhaps you could use
vfile-reporter
I linked above, or, perhaps you could useinspect
fromutil
: https://nodejs.org/api/util.html#utilinspectobject-options. I believe that it serializes recursivecause
sThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay yes this is the tricky bit.
In esbuild you can report errors by just throwing an exception, or by adding to a list of messages using their own
Message
class (which is what we're doing). That class includes adetail
field which can be an exception but could also be anything else, and in any case doesn't get printed in esbuild's output, it seems to be for custom API use; it's not really comparable tocause
.Alternatives
vfile-reporter
-- this does a fine job and does chase cause chains, unfortunately this wants an entireVFile
, I don't see a way to format a singleVFileMessage
(though you could imagine exposing that)?util.inspect
-- this has a lovely formatter forError
objects, but even for subclasses likeVFileMessage
reverts to its default printer which just dumps the fields and does not print error messages or chase cause chains?messages
-- this does get handled by esbuild gracefully (including plugin attribution), but the extra location information inVFileMessage
is lostVFileMessage
-shaped exceptions directly tomessages
(no wrapping), re-throw everything else, remove all cause-chain-processing -- this could work??For now I simplified the cause processing to not try to walk the whole cause chain but just include the string representation of the cause if one exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points, I appreciate that you came up with alternatives & discussed trade offs.
I could see an
reportError
invfile-reporter
, which can then be used here.The no-wrapping idea could also perhaps work.
But this is probably fine to start with!