feat: show all cause in Error#5422
Merged
lukastaegert merged 6 commits intorollup:masterfrom Apr 3, 2024
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5422 +/- ##
==========================================
- Coverage 98.80% 98.79% -0.01%
==========================================
Files 237 237
Lines 9432 9445 +13
Branches 2398 2403 +5
==========================================
+ Hits 9319 9331 +12
Misses 48 48
- Partials 65 66 +1 ☔ View full report in Codecov by Sentry. |
Member
There was a problem hiding this comment.
Hi, that looks already very good! Just two things:
- This looks very similar to how Node would print such an error. Node, however, would indent every subsequent cause by two more spaces (i.e. two for the first cause, four for the second etc.). Personally I find this helps visually so that it does not look like one huge stack trace. Maybe we want to add this as well? (one easy way to indent is to
.split('\n').map(line => indent+line).join('\n')) - It would be nice to test this output somewhat. Of course we should not test stack traces directly as they contain paths on a user's machine, but we can test stuff in between. Here is how you would do it:
If you do not know how to run tests, look at CONTRIBUTING.md.
Tests for command line output are located in test/cli. Create a new folder in test/cli/samples with the following files:
main.js: It does not matter a lot, but we need an entry point. E.g.console.log('ok')would be some content that does not produce a warning.rollup.config.mjs: We define a config that always throws an error with nested errors, e.g.export default { input: "main.js", plugins: [ { buildStart() { throw new Error("Outer error", { cause: new Error("Inner error", { cause: new Error("Innermost error") }) }); } } ] };
_config.js: The test configuration. This would be the typical contentsIf you addconst { assertIncludes } = require('../../../utils.js'); module.exports = defineTest({ description: 'prints error cause', command: 'rollup --config rollup.config.mjs', // We expect an error and want to make assertions about the output error: () => true, stderr: stderr => { // We just assert the parts of the output that do not change assertIncludes(stderr, '\n[!] (plugin at position 1) Error: Outer error\n at '); assertIncludes(stderr, '\n [cause] Error: Inner error\n at '); assertIncludes(stderr, '\n [cause] Error: Innermost error\n at '); } });
solo: true, you can just run this single test, just do not forget to remove this line before committing.
lukastaegert
approved these changes
Apr 3, 2024
|
This PR has been released as part of rollup@4.14.0. You can test it via |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers: #5166
Description
In ES2022+, Error has
causefield optionally. (type is unknown)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
So if
causeis in Error then show all cause log in cli.