Skip to content

src: add SetAbortHandler#64684

Open
maxhfisher wants to merge 4 commits into
nodejs:mainfrom
maxhfisher:aborthandler
Open

src: add SetAbortHandler#64684
maxhfisher wants to merge 4 commits into
nodejs:mainfrom
maxhfisher:aborthandler

Conversation

@maxhfisher

@maxhfisher maxhfisher commented Jul 22, 2026

Copy link
Copy Markdown

This adds SetAbortHandler, which allows embedders to specify custom behavior in situations where ABORT() is called. The current behavior of ABORT() is to stream both the native and JS backtraces to stderr and exit with platform specific behavior. Some embedders may want to change this behavior, such as changing where the backtrace is provided. Embedders can also use the handler to exit with their own behavior, but node will still guarantee an exit if the provided abort handler returns.

A DefaultAbortHandler is used to ensure existing behavior does not change unless an abort handler is explicitly provided. The only difference with this design is an additional stack frame in the backtrace for the abort handler, but this behavior was never guaranteed.

A new ABORT_WITH_MESSAGE macro is also added for cases where a message can be passed describing the reason for the abort. This new macro replaces existing calls to ABORT in various error handlers in node_errors.cc where a message is already available. This message is then propagated to the abort handler, but no changes are made to the default abort handler. That behavior does not change here.

Signed-off-by: Max H Fisher <mfisher187@bloomberg.net>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jul 22, 2026
Comment thread test/abort/test-addon-abort-handler.js Outdated
Comment thread src/node.h Outdated
Comment thread src/node.h Outdated
Comment thread src/node.h Outdated
Comment thread src/node_errors.cc Outdated
Comment thread src/node_errors.cc Outdated
Comment thread src/node.h Outdated
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.46154% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.12%. Comparing base (efc0a14) to head (71e66f8).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/node_errors.cc 38.46% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64684      +/-   ##
==========================================
+ Coverage   90.11%   90.12%   +0.01%     
==========================================
  Files         741      743       +2     
  Lines      242196   242334     +138     
  Branches    45606    45637      +31     
==========================================
+ Hits       218246   218398     +152     
- Misses      15438    15445       +7     
+ Partials     8512     8491      -21     
Files with missing lines Coverage Δ
src/node.h 92.30% <ø> (ø)
src/util.h 90.98% <ø> (ø)
src/node_errors.cc 62.58% <38.46%> (-0.18%) ⬇️

... and 72 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.

Signed-off-by: Max H Fisher <mfisher187@bloomberg.net>
Comment thread src/util.h Outdated
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants