From de914dc98797c67da1b03690ee5ac8853b809f2c Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 22 Nov 2026 22:27:21 +0000 Subject: [PATCH 1/2] src: add option to hide internal stack frames By default, when node.js prints a stack it includes all of the `node:internal` frames. This make the output more verbose but it's often providing extraneous detail the user can't do anything about. This adds a cli flag to hide those details. It can be set in NODE_OPTIONS. ```console $ node --hide-internal-stack-frames -e "require('node:fs').readFileSync('missing')" ... Error: ENOENT: no such file or directory, open 'missing' at Object.openSync (node:fs:779:18) at Object.readFileSync (node:fs:625:35) at [eval]:1:20 at (7 frames hidden) { ... ``` Signed-off-by: James M Snell Assisted-by: Claude --- doc/api/cli.md | 42 ++++++ doc/node-config-schema.json | 4 + doc/node.1 | 29 ++++ lib/internal/errors.js | 71 +++++++++- lib/internal/process/pre_execution.js | 18 ++- lib/internal/util/inspect.js | 3 +- src/node_errors.cc | 43 +++++- src/node_internals.h | 12 ++ src/node_options.cc | 4 + src/node_options.h | 1 + src/node_report.cc | 13 ++ src/node_watchdog.cc | 19 ++- .../test-hide-internal-stack-frames.js | 125 ++++++++++++++++++ 13 files changed, 372 insertions(+), 12 deletions(-) create mode 100644 test/parallel/test-hide-internal-stack-frames.js diff --git a/doc/api/cli.md b/doc/api/cli.md index abfbbeea45b1..f4f206f4b2a0 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1996,6 +1996,41 @@ added: v0.1.3 Print node command-line options. The output of this option is less detailed than this document. +### `--hide-internal-stack-frames` + + + +Collapse stack frames that originate from Node.js internal modules (those +whose file name starts with `node:internal/`), and from the wrapper scripts +Node.js generates around [`--eval`][] and stdin input, in printed stack +traces. Each +run of consecutive internal frames is replaced with a single +`at (N frames hidden)` line. Frames from user code and from +public built-in modules such as `node:fs` are kept. + +```console +$ node --hide-internal-stack-frames -e "require('node:fs').readFileSync('missing')" +... +Error: ENOENT: no such file or directory, open 'missing' + at Object.openSync (node:fs:779:18) + at Object.readFileSync (node:fs:625:35) + at [eval]:1:20 + at (7 frames hidden) { +... +``` + +This applies to `error.stack` and to the stack traces Node.js prints itself, +such as those from [`--trace-uncaught`][], [`--trace-exit`][], +[`--trace-sync-io`][], [`--process-timeout`][], and the JavaScript stack in a +[diagnostic report][]. + +Frames are collapsed after V8 collects them, so a trace still contains at most +[`Error.stackTraceLimit`][] frames. The flag affects only the default +formatter: an `Error.prepareStackTrace` function set by the user still +receives every frame, and [`util.getCallSites()`][] is unaffected. + ### `--icu-data-dir=file`