consola icon indicating copy to clipboard operation
consola copied to clipboard

feat: support report error `cause`

Open kongmoumou opened this issue 1 year ago • 2 comments

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 ⬇️

image

This PR support report error cause to console while used in node. Related issue #202

image

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"),
    }),
  }),
);

kongmoumou avatar Jul 09 '24 14:07 kongmoumou

Hi, @pi0 ~ What's your thought of this feature? Looking forward to your reply. 🫡

kongmoumou avatar Jul 30 '24 13:07 kongmoumou

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.

DrJume avatar Oct 13 '24 16:10 DrJume

@ pi0 Could you let me know any progress of this feat? Looking forward to ur thought~ 😂

kongmoumou avatar Dec 02 '24 13:12 kongmoumou

@kongmoumou it is on my list sorry got delayed (i might need to push small refactors before)

pi0 avatar Dec 02 '24 13:12 pi0

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.

codecov[bot] avatar Dec 02 '24 13:12 codecov[bot]

Thanks again and sorry it got delayed. I made few refactors + it is more consistent with Node.js stacks now:

image

pi0 avatar Dec 19 '24 22:12 pi0