Skip to content
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: include .cause stacks in the error stack traces #4829

Merged
merged 9 commits into from Mar 4, 2024

Conversation

voxpelli
Copy link
Member

@voxpelli voxpelli commented Feb 9, 2022

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions.

Description of the Change

Appends the full error stack chain for errors with causes.

Alternate Designs

Prior to the Error cause standardization, there was VError which I did a PR for supporting some years ago #2381. That one as primarily closed because an aversion to supporting random module hooks, which this now being a standard changes.

So I think this is now more a matter of:

  • Should this be on by default?
  • How should this be formatted?

Why should this be in core?

All current browsers supports this property and Node.js as well since 16.x.

See also eg:

Benefits

Error causes are a great way to enrich errors and to ensure that one can catch all relevant places across an async workflow. See also eg. this old Joyent article explaining how they uses VError.

Possible Drawbacks

  • It can become a bit too verbose if a lot of unnecessary causes gets printed, but is that an issue to take into consideration here?

Applicable issues

  • This would be a breaking change for everyone that relies on specific stack output for current error object's containing a stack possessing cause property, else it would be a minor. So depends on whether the specific stack output is seen as an API that should be stable or whether it's simply a presentation detail.

Fixes #2735.

@github-actions
Copy link

This PR hasn't had any recent activity, and I'm labeling it stale. Remove the label or comment or this PR will be closed in 14 days. Thanks for contributing to Mocha!

@github-actions github-actions bot added the stale this has been inactive for a while... label Jun 10, 2022
@voxpelli
Copy link
Member Author

Still relevant

@ephys
Copy link

ephys commented Sep 17, 2022

This PR looks good to me. We'd love for this to land. We had to implement some workarounds in the https://github.com/sequelize/sequelize test suites because our own error messages make heavy use of the cause property and the lack of support for them made them difficult to debug.

@github-actions
Copy link

This PR hasn't had any recent activity, and I'm labeling it stale. Remove the label or comment or this PR will be closed in 14 days. Thanks for contributing to Mocha!

@github-actions github-actions bot added the stale this has been inactive for a while... label Jan 16, 2023
@ephys
Copy link

ephys commented Jan 16, 2023

Would still love to see this merged

@voxpelli
Copy link
Member Author

Same here

@github-actions github-actions bot removed the stale this has been inactive for a while... label Jan 18, 2023
@github-actions
Copy link

This PR hasn't had any recent activity, and I'm labeling it stale. Remove the label or comment or this PR will be closed in 14 days. Thanks for contributing to Mocha!

@github-actions github-actions bot added the stale this has been inactive for a while... label May 19, 2023
@ephys
Copy link

ephys commented May 19, 2023

Labeling someone's work as stale because you haven't had time to review is not great :/

@github-actions github-actions bot removed the stale this has been inactive for a while... label May 22, 2023
@WikiRik
Copy link

WikiRik commented Jun 19, 2023

@juergba would be great if you could take a look at this. Node 16 is the oldest still supported version of Node so there are no supported versions anymore that do not have Error.cause

@github-actions
Copy link

This PR hasn't had any recent activity, and I'm labeling it stale. Remove the label or comment or this PR will be closed in 14 days. Thanks for contributing to Mocha!

@github-actions github-actions bot added the stale this has been inactive for a while... label Oct 18, 2023
@voxpelli
Copy link
Member Author

Still a lack of review, not this PR itself being stale

@github-actions github-actions bot removed the stale this has been inactive for a while... label Oct 20, 2023
@barak007
Copy link

barak007 commented Dec 5, 2023

Is this going to be merged? we want to start using the cause field in our errors.

@voxpelli voxpelli requested a review from a team December 5, 2023 15:57
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 excited to see cause support finally land!

We looked at this as a group, agreed with the general direction. Just a bit of edge case handling needed.

test/reporters/base.spec.js Outdated Show resolved Hide resolved
lib/reporters/base.js Outdated Show resolved Hide resolved
@voxpelli voxpelli changed the title Append the cause stacks to the Error stack traces feature: include .cause stacks in the error stack traces Feb 19, 2024
@voxpelli voxpelli changed the title feature: include .cause stacks in the error stack traces feat: include .cause stacks in the error stack traces Feb 19, 2024
@coveralls
Copy link

coveralls commented Feb 19, 2024

Coverage Status

coverage: 94.359% (+0.02%) from 94.335%
when pulling 571ac7c on voxpelli:support-error-causes
into b88978d on mochajs:master.

@voxpelli
Copy link
Member Author

Included support for #4128 style messages in the cause trail in this update as well, making the stack traces more comparable between top error and cause trail

Only thing that's unique to the top error now: Support for pretty chai / assert diffs.

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 LGTM! Just a couple of small suggestions, nothing big. Nicely done!

lib/runner.js Show resolved Hide resolved
lib/reporters/base.js Show resolved Hide resolved
lib/reporters/base.js Show resolved Hide resolved
@voxpelli
Copy link
Member Author

@JoshuaKGoldberg Looks like our linting hasn't understood that ?. is okay yet 😜

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Feb 20, 2024

😭

I suppose once we convert to TypeScript & enable the strictest of the typescript-eslint presets, I suppose it'll be caught for us. 😄

(this comment is in jest and does not commit us to any migrations)

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(since the past review was dismissed automatically by GitHub)

lib/runner.js Outdated
const alreadyFiltered = new Set();
let currentErr = err;

while (currentErr?.stack && !alreadyFiltered.has(currentErr)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?.

From https://github.com/mochajs/mocha/actions/runs/8068123423/job/22040196920?pr=4829:

nps is executing `build` : rollup -c ./rollup.config.js

./browser-entry.js → ./mocha.js...
[!] (plugin at position 4) SyntaxError: Unexpected token (467:22) in /home/runner/work/mocha/mocha/lib/runner.js
lib/runner.js (467:22)
SyntaxError: Unexpected token (467:22) in /home/runner/work/mocha/mocha/lib/runner.js
    at Parser.pp$4.raise (/home/runner/work/mocha/mocha/node_modules/rollup-plugin-node-globals/node_modules/acorn/dist/acorn.js:2757:13)

@voxpelli what do you want to do here? My intuition is to delay using ?. until we redo the rollup builds / etc..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, removing it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now 0 for 2 in making suggestions on this PR. Not great for me. 😂

@JoshuaKGoldberg JoshuaKGoldberg added the semver-minor implementation requires increase of "minor" version number; "features" label Mar 4, 2024
@voxpelli voxpelli merged commit 3735873 into mochajs:master Mar 4, 2024
25 of 26 checks passed
@voxpelli voxpelli deleted the support-error-causes branch March 4, 2024 14:27
@voxpelli
Copy link
Member Author

Included in v10.4.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor implementation requires increase of "minor" version number; "features"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: Add support for outputting Error cause
6 participants