Skip to content

process: expose enhanced stack trace to uncaughtException handlers - #65849

Closed
santusht06 wants to merge 1 commit into
nodejs:mainfrom
santusht06:pr-65812
Closed

process: expose enhanced stack trace to uncaughtException handlers#65849
santusht06 wants to merge 1 commit into
nodejs:mainfrom
santusht06:pr-65812

Conversation

@santusht06

Copy link
Copy Markdown

Summary

Fixes #55838.

When an EventEmitter emits an unhandled 'error' event, V8 appends an
Emitted 'error' event at: frame to the stack trace via the inspector stack
trace enhancer. However, this enhancement was applied only during the default
fatal-exception path (inside fatalException()), after the
uncaughtException and uncaughtExceptionMonitor handlers had already been
invoked, so user-registered handlers never saw the enriched stack.

Root Cause

fatalExceptionStackEnhancers.beforeInspector() was called inside
fatalException() — the final, process-exiting path — but not inside
createOnGlobalUncaughtException() which fires the user handlers first.

Fix

Call fatalExceptionStackEnhancers.beforeInspector(er) inside
createOnGlobalUncaughtException() before emitting to
uncaughtExceptionMonitor and uncaughtException. The guard
er != null && typeof er === 'object' safely handles primitive throws.

Testing

Added test/parallel/test-process-uncaught-exception-enhanced-stack.js which
verifies both a plain EventEmitter and a subclass expose the Emitted 'error' event at:
frame to both handlers.

$ ./out/Release/node test/parallel/test-process-uncaught-exception-enhanced-stack.js
# exit 0 ✅

Signed-off-by: santusht06 115890693+santusht06@users.noreply.github.com
Assisted-by: Antigravity

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. labels Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Caution

AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context.

When an EventEmitter emits an unhandled 'error' event, V8 appends an
'Emitted \'error\' event at:' frame to the stack trace via the inspector
stack trace enhancer. However, this enhancement was applied only during
the default fatal-exception path (inside fatalException()), after the
uncaughtException and uncaughtExceptionMonitor handlers had already been
invoked, so user-registered handlers never saw the enriched stack.

Fix this by calling fatalExceptionStackEnhancers.beforeInspector() in
createOnGlobalUncaughtException() before dispatching to the handlers.

Fixes: nodejs#55838
Assisted-by: Antigravity
Signed-off-by: santusht06 <115890693+santusht06@users.noreply.github.com>
@santusht06
santusht06 marked this pull request as draft September 6, 2026 10:09
@santusht06

Copy link
Copy Markdown
Author

I used AI assistance to help prepare this PR, personally verified and tested all changes locally, and take full responsibility for this submission.

@MikeMcC399

Copy link
Copy Markdown
Contributor

The recommendations in:

advise you should tackle only one issue at a time and that you should not open any new PRs until your first PR has been approved.

You already have other unapproved PRs open:

@santusht06

Copy link
Copy Markdown
Author

Apologies for the noise and duplicate PR! Closing this as it is an accidental duplicate of #65580. Thank you for pointing that out, @MikeMcC399.

@santusht06 santusht06 closed this Sep 6, 2026
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.17%. Comparing base (7991140) to head (2fcd2bd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65849      +/-   ##
==========================================
- Coverage   90.19%   90.17%   -0.02%     
==========================================
  Files         771      771              
  Lines      264622   264627       +5     
  Branches    50223    50225       +2     
==========================================
- Hits       238663   238634      -29     
- Misses      16965    16974       +9     
- Partials     8994     9019      +25     
Files with missing lines Coverage Δ
lib/internal/process/execution.js 99.23% <100.00%> (-0.77%) ⬇️

... and 33 files with indirect coverage changes

🚀 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

agentscan:automated-account module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the "enhanced" stack trace from uncaught exceptions to the uncaughtException and uncaughtExceptionMonitor handlers on process

3 participants