Skip to content

Commit 7349d42

Browse files
addaleaxcjihrig
authored andcommitted
cli: add --stack-trace-limit to NODE_OPTIONS
I decided that it would make a lot of sense for me to set `NODE_OPTIONS=--stack-trace-limit=100` on my development machine. This code allows me to do that. :) PR-URL: #16495 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ryan Graham <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent d5ea177 commit 7349d42

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

doc/api/cli.md

+1
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ Node options that are allowed are:
471471
V8 options that are allowed are:
472472
- `--abort-on-uncaught-exception`
473473
- `--max-old-space-size`
474+
- `--stack-trace-limit`
474475

475476
### `NODE_PENDING_DEPRECATION=1`
476477
<!-- YAML

src/node.cc

+1
Original file line numberDiff line numberDiff line change
@@ -4051,6 +4051,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
40514051
// V8 options (define with '_', which allows '-' or '_')
40524052
"--abort_on_uncaught_exception",
40534053
"--max_old_space_size",
4054+
"--stack_trace_limit",
40544055
};
40554056

40564057
for (unsigned i = 0; i < arraysize(whitelist); i++) {

test/parallel/test-cli-node-options.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,26 @@ if (common.hasCrypto) {
3333
// V8 options
3434
expect('--abort_on-uncaught_exception', 'B\n');
3535
expect('--max-old-space-size=0', 'B\n');
36+
expect('--stack-trace-limit=100',
37+
/(\s*at f \(\[eval\]:1:\d*\)\n){100}/,
38+
'(function f() { f(); })();',
39+
true);
3640

37-
function expect(opt, want) {
38-
const argv = ['-e', 'console.log("B")'];
41+
function expect(opt, want, command = 'console.log("B")', wantsError = false) {
42+
const argv = ['-e', command];
3943
const opts = {
4044
env: Object.assign({}, process.env, { NODE_OPTIONS: opt }),
4145
maxBuffer: 1e6,
4246
};
43-
exec(process.execPath, argv, opts, common.mustCall((err, stdout) => {
44-
assert.ifError(err);
45-
if (stdout.includes(want)) return;
47+
if (typeof want === 'string')
48+
want = new RegExp(want);
49+
exec(process.execPath, argv, opts, common.mustCall((err, stdout, stderr) => {
50+
if (wantsError) {
51+
stdout = stderr;
52+
} else {
53+
assert.ifError(err);
54+
}
55+
if (want.test(stdout)) return;
4656

4757
const o = JSON.stringify(opt);
4858
assert.fail(`For ${o}, failed to find ${want} in: <\n${stdout}\n>`);

0 commit comments

Comments
 (0)