-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3d2e68e
improve error reporting from esbuild plugin (WIP)
egnor d3d13e1
fix coverage
egnor 199439e
fix tsc errors
egnor ed891fc
Update packages/esbuild/lib/index.js
egnor 377c6e4
Update packages/esbuild/test/index.js
egnor 0b85289
Update packages/esbuild/test/index.js
egnor bbe4f87
merge cause into message when converting to esbuild message, not when…
egnor 2b32e26
avoid instanceof for imported types
egnor 3dffdcf
fix tsc
egnor a89028b
ran npm test
egnor d3c901f
simplify cause reporting
egnor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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!