Skip to content

fix(reporter): surface JSON.stringify failures in json reporter instead of silently succeeding#41620

Open
Git-Raini wants to merge 1 commit into
microsoft:mainfrom
Git-Raini:fix-40983
Open

fix(reporter): surface JSON.stringify failures in json reporter instead of silently succeeding#41620
Git-Raini wants to merge 1 commit into
microsoft:mainfrom
Git-Raini:fix-40983

Conversation

@Git-Raini

Copy link
Copy Markdown
Contributor

Fixes #40983

  • Wrap the JSON.stringify call in the JSON reporter's outputReport with a try/catch that rethrows a clear, actionable error (e.g. when hitting V8's max string length on very large merged reports) instead of letting a raw RangeError surface with no context
  • The error still propagates through the existing reporter-error mechanism, so the run/merge command now correctly exits non-zero instead of silently succeeding with a 0-byte report

…ad of silently succeeding

Wrap JSON.stringify in outputReport() so a RangeError (report too large
for a JS string) is rethrown as a clear, actionable error instead of
propagating a cryptic V8 error. The existing reporter-error mechanism
(Multiplexer.hasReporterErrors, added in microsoft#41307) already fails the run/
merge command with a non-zero exit code once onEnd throws, so this makes
the json reporter benefit from that instead of producing a missing/empty
report file with exit code 0.

Fixes: microsoft#40983
// string would exceed the JS engine's max string length (e.g. for very large merged
// reports). Surface this as a real, actionable error instead of silently producing
// a missing/empty report file - the caller (reporter/merge command) will fail the run.
throw new Error(`Failed to generate JSON report: the report is too large to serialize (${e instanceof Error ? e.message : String(e)}). Consider splitting the run into smaller shards or using a different reporter.`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we match actual error that we know is caused by a too large report and wrap the error only in that case or rephrase message. Also remove the comment.

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.

[Bug]: JSON reporter silently produces 0-byte file when merged report exceeds V8 max string length

2 participants