Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: suggest --trace-warnings when printing warning #32797

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/internal/process/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function doEmitWarning(warning) {
return () => process.emit('warning', warning);
}

let traceWarningHelperShown = false;
function onWarning(warning) {
if (!(warning instanceof Error)) return;
const isDeprecation = warning.name === 'DeprecationWarning';
Expand All @@ -78,6 +79,13 @@ function onWarning(warning) {
if (typeof warning.detail === 'string') {
msg += `\n${warning.detail}`;
}
if (!trace && !traceWarningHelperShown) {
const flag = isDeprecation ? '--trace-deprecation' : '--trace-warnings';
const argv0 = require('path').basename(process.argv0 || 'node');
msg += `\n(Use \`${argv0} ${flag} ...\` to show where the warning ` +
'was created)';
traceWarningHelperShown = true;
}
const warningFile = lazyOption();
if (warningFile) {
return writeToFile(msg);
Expand Down
1 change: 1 addition & 0 deletions test/message/async_error_sync_esm.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
Error: test
at one (*fixtures*async-error.js:4:9)
at two (*fixtures*async-error.js:17:9)
Expand Down
1 change: 1 addition & 0 deletions test/message/esm_display_syntax_error.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
file:///*/test/message/esm_display_syntax_error.mjs:2
await async () => 0;
^^^^^
Expand Down
1 change: 1 addition & 0 deletions test/message/esm_display_syntax_error_import.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
file:///*/test/message/esm_display_syntax_error_import.mjs:5
notfound
^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions test/message/esm_display_syntax_error_import_module.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1
import { foo, notfound } from './module-named-exports.mjs';
^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion test/message/esm_display_syntax_error_module.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
file:///*/test/fixtures/es-module-loaders/syntax-error.mjs:2
await async () => 0;
^^^^^

SyntaxError: Unexpected reserved word
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
1 change: 1 addition & 0 deletions test/message/esm_loader_not_found.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
internal/modules/run_main.js:*
internalBinding('errors').triggerUncaughtException(
Expand Down
1 change: 1 addition & 0 deletions test/message/esm_loader_syntax_error.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(node:*) ExperimentalWarning: The ESM module loader is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
file://*/test/fixtures/es-module-loaders/syntax-error.mjs:2
await async () => 0;
Expand Down
1 change: 1 addition & 0 deletions test/message/v8_warning.out
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
(node:*) V8: *v8_warning.js:* Invalid asm.js: Invalid return type
(Use `node --trace-warnings ...` to show where the warning was created)
7 changes: 5 additions & 2 deletions test/parallel/test-debugger-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ interfacer.on('line', function(line) {
case 1:
expected =
new RegExp(`^\\(node:${pid}\\) \\[DEP0068\\] DeprecationWarning: `);
assert.ok(expected.test(line), `expected regexp match for ${line}`);
assert.match(line, expected);
break;
case 2:
assert.match(line, /Use `node --trace-deprecation \.\.\.` to show where /);
break;
case 3:
// Doesn't currently work on Windows.
if (!common.isWindows) {
expected = "Target process: 655555 doesn't exist.";
Expand All @@ -48,6 +51,6 @@ interfacer.on('line', function(line) {
interfacer.on('exit', function(code, signal) {
assert.strictEqual(code, 1, `Got unexpected code: ${code}`);
if (!common.isWindows) {
assert.strictEqual(lineCount, 2);
assert.strictEqual(lineCount, 3);
}
});
2 changes: 1 addition & 1 deletion test/parallel/test-env-var-no-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (process.argv[2] === 'child') {
if (env.NODE_NO_WARNINGS === '1')
assert.strictEqual(stderr, '');
else
assert(/Warning: foo$/.test(stderr.trim()));
assert.match(stderr.trim(), /Warning: foo\n/);
}));
}

Expand Down
1 change: 1 addition & 0 deletions test/pseudo-tty/test-tty-color-support-warning-2.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
(Use `node --trace-warnings ...` to show where the warning was created)
1 change: 1 addition & 0 deletions test/pseudo-tty/test-tty-color-support-warning.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use `node --trace-warnings ...` to show where the warning was created)
1 change: 1 addition & 0 deletions test/pseudo-tty/test-tty-color-support.out
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use `node --trace-warnings ...` to show where the warning was created)