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
feat: show all cause in Error #5422
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. |
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.
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.
This PR has been released as part of rollup@4.14.0. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers: #5166
Description
In ES2022+, Error has
cause
field optionally. (type is unknown)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
So if
cause
is in Error then show all cause log in cli.