feat: support report error `cause`
The cause property of Error had been support in most runtime and been widely adapted by many repo.
The Chrome devtool already support showing caused error like screenshot below ⬇️
This PR support report error cause to console while used in node. Related issue #202
Test code provided:
import { consola } from "./src/index";
consola.error(
new Error("This is an error", {
cause: new Error("This is the cause", {
cause: new Error("This is the cause of the cause"),
}),
}),
);
Hi, @pi0 ~ What's your thought of this feature? Looking forward to your reply. 🫡
This would be so good to have! The cause adds important context in many errors (e.g. fetch errors with undici). I didn't know that consola hides it and lost some time because of it, because I didn't get all information from the error.
Also the name/type of the error (e.g. "TypeError: ") gets lost with consola.
@ pi0 Could you let me know any progress of this feat? Looking forward to ur thought~ 😂
@kongmoumou it is on my list sorry got delayed (i might need to push small refactors before)
Codecov Report
Attention: Patch coverage is 7.69231% with 24 lines in your changes missing coverage. Please review.
Project coverage is 21.99%. Comparing base (
24c98ce) to head (2677efa). Report is 23 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/reporters/basic.ts | 7.69% | 12 Missing :warning: |
| examples/error.ts | 0.00% | 8 Missing and 1 partial :warning: |
| src/reporters/fancy.ts | 25.00% | 3 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #308 +/- ##
===========================================
- Coverage 61.08% 21.99% -39.09%
===========================================
Files 13 43 +30
Lines 1380 2191 +811
Branches 58 88 +30
===========================================
- Hits 843 482 -361
- Misses 537 1681 +1144
- Partials 0 28 +28
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Thanks again and sorry it got delayed. I made few refactors + it is more consistent with Node.js stacks now: