Skip to content

prevent poisoned diffs from suppressing non-zero exits #5998

Open
mostafaNazari702 wants to merge 1 commit into
mochajs:mainfrom
mostafaNazari702:reporter-crash-zeroexit
Open

prevent poisoned diffs from suppressing non-zero exits #5998
mostafaNazari702 wants to merge 1 commit into
mochajs:mainfrom
mostafaNazari702:reporter-crash-zeroexit

Conversation

@mostafaNazari702

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

This PR is the last of the wave. there was was a broader issue behind #5505/#5506 where reporter-side errors could cause nocha to exit with status 0 even though the run actually failed.

if the Base reporter threw while handling a failed test. either during EVENT_TEST_FAIL or later in Base.list during the epilougue , the exception could break mocha's internal runner flow before the final failure count was reported to the CLI. The run looked failed in output, but the process still exited successfully.
the original repro using Object.create(null) was fixed already but i guess the underlying issue still existed for anything that could make utils.stringify or diff rendering throw (hostile proxies, throwing getters, weird objects, etc......).

we now got defensive handling in the lib/reporters/base.js file at three levels, stringifyDiffObjs now safely falls back if object stringification throws. the EVENT_TEST_FAIL listener is wrapped so reporter errors are logged to stderrr instead of breaking the run. Base.list now isolates rendering failures per test so one broken failure output doesn’t abort the entire epilogue

…diff payload no longer suppresses the non-zero exit code
@mostafaNazari702

Copy link
Copy Markdown
Contributor Author

I used some questionable terminologies such as reslience but i want you guys to evaluate, your opinions matter as well. I just couldn't find a better word to have instead there.

@mostafaNazari702 mostafaNazari702 changed the title prevent poisoned diffs from suppressing non-zero exits prevent poisoned diffs from suppressing non-zero exits May 22, 2026
@mostafaNazari702

mostafaNazari702 commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

So i while i was typing "Added a space in the end of the PR title to re-run tests", the error to tests even after re-running, appeared...Can you guys tell if that is an issue caused on my side?

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.06%. Comparing base (6695fba) to head (794d87d).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
lib/reporters/base.js 89.47% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5998      +/-   ##
==========================================
+ Coverage   80.89%   81.06%   +0.16%     
==========================================
  Files          64       64              
  Lines        4602     4621      +19     
  Branches      976     1001      +25     
==========================================
+ Hits         3723     3746      +23     
+ Misses        879      875       -4     

☔ 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.

@JoshuaKGoldberg JoshuaKGoldberg left a comment

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.

@mostafaNazari702 this has lint failures, I'll wait to review until they're fixed.

https://github.com/mochajs/mocha/actions/runs/26314852116/job/77471707014?pr=5998

/home/runner/work/mocha/mocha/lib/reporters/base.js
Error:   106:17  error  Empty block statement  no-empty
Error:   110:17  error  Empty block statement  no-empty
Error:   490:15  error  Empty block statement  no-empty

@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author waiting on response from OP or other posters - more information needed label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting for author waiting on response from OP or other posters - more information needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: unhandledRejection in the default Runner kills process with 0 status code

2 participants