mocha icon indicating copy to clipboard operation
mocha copied to clipboard

feat: support reporting AggregateErrors

Open CheadleCheadle opened this issue 2 years ago • 5 comments

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.

CheadleCheadle avatar Oct 19 '23 00:10 CheadleCheadle

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

wesleytodd avatar Feb 02 '24 15:02 wesleytodd

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?

nwalters512 avatar Feb 02 '24 15:02 nwalters512

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

CheadleCheadle avatar Feb 02 '24 15:02 CheadleCheadle

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

voxpelli avatar Feb 02 '24 16:02 voxpelli

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:

  • https://github.com/mochajs/mocha/pull/5074
  • #4829

voxpelli avatar Feb 19 '24 11:02 voxpelli