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: support reporting AggregateErrors #5018

Closed
wants to merge 17 commits into from

Conversation

CheadleCheadle
Copy link

@CheadleCheadle CheadleCheadle commented Oct 19, 2023

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

Addresses #4982
If an AggregateError is thrown, the base reporter will print out the AggregateError's errors. Before this change, only the Aggregate Error itself was printed. So, if the current error being printed is an Aggregate error the errors it contains will also be formatted and printed.

Alternate Designs

I could have completely restructured the Base.list method to only loop over the failures and call a helper function that would create the format(fmt), msg, and title and then print the error, but it was much simpler to just add a conditional check to see if the current error being printed was an AggregateError and if it contained multiple errors and just

Why should this be in core?

Currently, nothing nice prints. When dealing with AggregateErrors it would be better if each subsequent error was printed and formatted as well.

Benefits

The errors within the AggregateError will be nicely formatted when printed.

Possible Drawbacks

If an AggregateError contains a lot of errors, then a lot of errors will be printed!

Applicable issues

Nothing of note.

Copy link
Member

@voxpelli voxpelli left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! 🙏

Some initial feedback

lib/cli/run-option-metadata.js Outdated Show resolved Hide resolved
lib/reporters/base.js Outdated Show resolved Hide resolved
lib/reporters/base.js Show resolved Hide resolved
lib/reporters/base.js Outdated Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
lib/reporters/json.js Outdated Show resolved Hide resolved
@wesleytodd
Copy link

Plus one on this. I just ran into it. Is anyone working on this anymore? It looks like maybe the feedback was addressed?

@nwalters512
Copy link

Somewhere between Node 16 and Node 20, Node's own APIs started throwing AggregateError in certain cases, e.g. network failures when autoSelectFamily === true (the default). Without proper formatting, it's very difficult to debug such errors when they occur in Mocha tests. Is there anything we can do to help this along?

@CheadleCheadle
Copy link
Author

I addressed all the changes and sent an email to voxpelli to see if he could approve it.

@voxpelli
Copy link
Member

voxpelli commented Feb 2, 2024

I'll try to get around to it soon, else eg. @JoshuaKGoldberg can chime in?

lib/reporters/base.js Outdated Show resolved Hide resolved
Modified check for if an error is an instance of an AggregateError when recursively printing errors
@voxpelli
Copy link
Member

I'm running out of time to review and merge this today, but this one together with these two are my main priority right now:

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.

Good start! 🙌

I'd also like to hear from @voxpelli, but leaving some thoughts in the meantime too.

lib/cli/run-option-metadata.js Outdated Show resolved Hide resolved
bin/mocha.js Outdated Show resolved Hide resolved
lib/reporters/base.js Outdated Show resolved Hide resolved
lib/reporters/base.js Show resolved Hide resolved
test/reporters/base.spec.js Outdated Show resolved Hide resolved
test/reporters/base.spec.js Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author waiting on response from OP - more information needed semver-minor implementation requires increase of "minor" version number; "features" labels Mar 4, 2024
@JoshuaKGoldberg JoshuaKGoldberg changed the title Aggregate error feat: support reporting AggregateErrors Mar 4, 2024
bin/mocha.js Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Still the permissions change? Is there an automatic modification happening on save or something like that?

Copy link
Author

Choose a reason for hiding this comment

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

It's possible. I'll look into it this week.

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.

Whoops, I'd meant to post this a bit back, sorry - but looks like there are failing tests?

Comment on lines +301 to +305
} else if (test.err) {
err = test.err;
} else {
// Handles when failures is a list of errors and not test objects.
err = test;
Copy link
Member

Choose a reason for hiding this comment

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

[Style] ✨

Suggested change
} else if (test.err) {
err = test.err;
} else {
// Handles when failures is a list of errors and not test objects.
err = test;
} else if (test.err) {
// Handles when failures is a list of errors and not test objects.
err = test.err || test;

Copy link
Member

Choose a reason for hiding this comment

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

@CheadleCheadle there are tests failing, could you please take a look?

Note that I just pulled the latest changes in from main (renamed from master). They didn't fix the test failure.

@JoshuaKGoldberg
Copy link
Member

👋 Ping @CheadleCheadle, is this still something you have energy & time for?

@JoshuaKGoldberg JoshuaKGoldberg added the stale this has been inactive for a while... label Oct 8, 2024
@nwalters512
Copy link

@JoshuaKGoldberg I'm very interested in seeing this land. What's the best way for me to help, open PRs against this branch? Or open a brand-new PR with these same changes?

@voxpelli
Copy link
Member

@nwalters512 Brand new PR would be the way to go I would say, that references this one and the original issue in it’s description

@JoshuaKGoldberg
Copy link
Member

Yeah, this has been stale for a while. I think it's safe to close out.

If you end up using code from this PR, please add a co-author attribution. Otherwise 🚀 free to make a new one!

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" stale this has been inactive for a while... status: waiting for author waiting on response from OP - more information needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants