mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
process: suggest --trace-warnings when printing warning
Suggest using `--trace-warnings` or `--trace-deprecation` the first time a warning is emitted without a stack trace, similar to how we suggest `--trace-uncaught` when printing uncaught exceptions without a stack trace. PR-URL: https://github.com/nodejs/node/pull/32797 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
@@ -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';
|
||||
@@ -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', '.exe');
|
||||
msg += `\n(Use \`${argv0} ${flag} ...\` to show where the warning ` +
|
||||
'was created)';
|
||||
traceWarningHelperShown = true;
|
||||
}
|
||||
const warningFile = lazyOption();
|
||||
if (warningFile) {
|
||||
return writeToFile(msg);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
^^^^^
|
||||
|
||||
@@ -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
|
||||
^^^^^^^^
|
||||
|
||||
@@ -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';
|
||||
^^^^^^^^
|
||||
|
||||
@@ -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,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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.";
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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/);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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 +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)
|
||||
|
||||
Reference in New Issue
Block a user