Skip to content

feat: print each error within AggregateErrors - #6120

Open
gaurav0107 wants to merge 1 commit into
mochajs:mainfrom
gaurav0107:fix/4982-feature-support-printing-each-error-with
Open

feat: print each error within AggregateErrors#6120
gaurav0107 wants to merge 1 commit into
mochajs:mainfrom
gaurav0107:fix/4982-feature-support-printing-each-error-with

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

When a test throws an AggregateError, reporters only printed the top-level message and stack; the individual errors in error.errors were dropped. This extends getFullErrorStack in lib/reporters/base.js to traverse err.errors and append each contained error (message + stack), reusing the same recursive formatting as the existing err.cause trail.

  • Nested aggregates and cause chains inside aggregated errors render via the same recursion.
  • Non-Error entries (an AggregateError may be constructed with any iterable) are stringified rather than crashing the reporter.
  • Circular references are guarded by the existing seen set.

Output for an AggregateError:

  1) test:
     AggregateError: 2 things went wrong
      <stack>
     Aggregated error: Error: first failure
      <stack>
     Aggregated error: TypeError: second failure
      <stack>

Unit tests added in test/reporters/base.spec.cjs cover multiple/single/non-Error/nested/circular cases.

getFullErrorStack now traverses err.errors so the reporters append each
error contained in an AggregateError (message + stack), reusing the same
recursive formatting as the existing err.cause trail. Non-Error entries
are stringified and circular references are guarded via the shared seen
set.

Fixes mochajs#4982
@gaurav0107
gaurav0107 marked this pull request as ready for review June 28, 2026 21:17
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.42%. Comparing base (7ad398e) to head (f8e0524).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6120      +/-   ##
==========================================
+ Coverage   82.38%   82.42%   +0.03%     
==========================================
  Files          61       61              
  Lines        4564     4574      +10     
  Branches      958      964       +6     
==========================================
+ Hits         3760     3770      +10     
  Misses        804      804              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: Support printing each error within AggregateErrors

1 participant