Skip to content

Commit

Permalink
cli: add --stack-trace-limit to NODE_OPTIONS
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
addaleax authored and cjihrig committed Nov 6, 2017
1 parent d5ea177 commit 7349d42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ Node options that are allowed are:
V8 options that are allowed are:
- `--abort-on-uncaught-exception`
- `--max-old-space-size`
- `--stack-trace-limit`

### `NODE_PENDING_DEPRECATION=1`
<!-- YAML
Expand Down
1 change: 1 addition & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4051,6 +4051,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
// V8 options (define with '_', which allows '-' or '_')
"--abort_on_uncaught_exception",
"--max_old_space_size",
"--stack_trace_limit",
};

for (unsigned i = 0; i < arraysize(whitelist); i++) {
Expand Down
20 changes: 15 additions & 5 deletions test/parallel/test-cli-node-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ if (common.hasCrypto) {
// V8 options
expect('--abort_on-uncaught_exception', 'B\n');
expect('--max-old-space-size=0', 'B\n');
expect('--stack-trace-limit=100',
/(\s*at f \(\[eval\]:1:\d*\)\n){100}/,
'(function f() { f(); })();',
true);

function expect(opt, want) {
const argv = ['-e', 'console.log("B")'];
function expect(opt, want, command = 'console.log("B")', wantsError = false) {
const argv = ['-e', command];
const opts = {
env: Object.assign({}, process.env, { NODE_OPTIONS: opt }),
maxBuffer: 1e6,
};
exec(process.execPath, argv, opts, common.mustCall((err, stdout) => {
assert.ifError(err);
if (stdout.includes(want)) return;
if (typeof want === 'string')
want = new RegExp(want);
exec(process.execPath, argv, opts, common.mustCall((err, stdout, stderr) => {
if (wantsError) {
stdout = stderr;
} else {
assert.ifError(err);
}
if (want.test(stdout)) return;

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

0 comments on commit 7349d42

Please sign in to comment.