From ca9520a9786c781d302c41df2d7d9d704aa123b8 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 12 Apr 2020 18:11:14 +0200 Subject: [PATCH 1/3] 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. --- lib/internal/process/warning.js | 7 +++++++ test/message/async_error_sync_esm.out | 1 + test/message/esm_display_syntax_error.out | 1 + test/message/esm_display_syntax_error_import.out | 1 + test/message/esm_display_syntax_error_import_module.out | 1 + test/message/esm_display_syntax_error_module.out | 3 ++- test/message/esm_loader_not_found.out | 1 + test/message/esm_loader_syntax_error.out | 1 + test/message/v8_warning.out | 1 + test/parallel/test-debugger-pid.js | 7 +++++-- test/parallel/test-env-var-no-warnings.js | 2 +- test/pseudo-tty/test-tty-color-support-warning-2.out | 1 + test/pseudo-tty/test-tty-color-support-warning.out | 1 + test/pseudo-tty/test-tty-color-support.out | 1 + 14 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 4a2ce2d6b203c8..490de2f0caeec1 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -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,12 @@ function onWarning(warning) { if (typeof warning.detail === 'string') { msg += `\n${warning.detail}`; } + if (!trace && !traceWarningHelperShown) { + const flag = isDeprecation ? '--trace-deprecation' : '--trace-warnings'; + msg += `\n(Use \`node ${flag} ...\` to show where the warning ` + + 'was created)'; + traceWarningHelperShown = true; + } const warningFile = lazyOption(); if (warningFile) { return writeToFile(msg); diff --git a/test/message/async_error_sync_esm.out b/test/message/async_error_sync_esm.out index 6577fff6944723..abaa2524cff3b8 100644 --- a/test/message/async_error_sync_esm.out +++ b/test/message/async_error_sync_esm.out @@ -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) diff --git a/test/message/esm_display_syntax_error.out b/test/message/esm_display_syntax_error.out index 778d901129fa95..382d459c2e67dd 100644 --- a/test/message/esm_display_syntax_error.out +++ b/test/message/esm_display_syntax_error.out @@ -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; ^^^^^ diff --git a/test/message/esm_display_syntax_error_import.out b/test/message/esm_display_syntax_error_import.out index e39744a049b59b..d24891bd2c0df0 100644 --- a/test/message/esm_display_syntax_error_import.out +++ b/test/message/esm_display_syntax_error_import.out @@ -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 ^^^^^^^^ diff --git a/test/message/esm_display_syntax_error_import_module.out b/test/message/esm_display_syntax_error_import_module.out index 0daaeff5b95daf..aaf65069bc4f18 100644 --- a/test/message/esm_display_syntax_error_import_module.out +++ b/test/message/esm_display_syntax_error_import_module.out @@ -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'; ^^^^^^^^ diff --git a/test/message/esm_display_syntax_error_module.out b/test/message/esm_display_syntax_error_module.out index a1498f72c94d57..c22bf0437c56a7 100644 --- a/test/message/esm_display_syntax_error_module.out +++ b/test/message/esm_display_syntax_error_module.out @@ -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:*:*) \ No newline at end of file + at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*) diff --git a/test/message/esm_loader_not_found.out b/test/message/esm_loader_not_found.out index a054dacf2f930a..0949c4d0e3ace6 100644 --- a/test/message/esm_loader_not_found.out +++ b/test/message/esm_loader_not_found.out @@ -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( diff --git a/test/message/esm_loader_syntax_error.out b/test/message/esm_loader_syntax_error.out index 9767a9c86c6bc2..cde6bd0aa811f8 100644 --- a/test/message/esm_loader_syntax_error.out +++ b/test/message/esm_loader_syntax_error.out @@ -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; diff --git a/test/message/v8_warning.out b/test/message/v8_warning.out index 7943d0e9d64dfe..b006af0518f0f4 100644 --- a/test/message/v8_warning.out +++ b/test/message/v8_warning.out @@ -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) diff --git a/test/parallel/test-debugger-pid.js b/test/parallel/test-debugger-pid.js index f269ff310b145c..00f14b2cf5bb61 100644 --- a/test/parallel/test-debugger-pid.js +++ b/test/parallel/test-debugger-pid.js @@ -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); } }); diff --git a/test/parallel/test-env-var-no-warnings.js b/test/parallel/test-env-var-no-warnings.js index cf90c2759d9ad7..b6164da1039a55 100644 --- a/test/parallel/test-env-var-no-warnings.js +++ b/test/parallel/test-env-var-no-warnings.js @@ -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/); })); } diff --git a/test/pseudo-tty/test-tty-color-support-warning-2.out b/test/pseudo-tty/test-tty-color-support-warning-2.out index cd57b3f9f69672..d17fa99b96974a 100644 --- a/test/pseudo-tty/test-tty-color-support-warning-2.out +++ b/test/pseudo-tty/test-tty-color-support-warning-2.out @@ -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) diff --git a/test/pseudo-tty/test-tty-color-support-warning.out b/test/pseudo-tty/test-tty-color-support-warning.out index 9360ae1328b2cd..7a9df4725486d2 100644 --- a/test/pseudo-tty/test-tty-color-support-warning.out +++ b/test/pseudo-tty/test-tty-color-support-warning.out @@ -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) diff --git a/test/pseudo-tty/test-tty-color-support.out b/test/pseudo-tty/test-tty-color-support.out index e6904d10b8a7b8..86ed488ee8c1b2 100644 --- a/test/pseudo-tty/test-tty-color-support.out +++ b/test/pseudo-tty/test-tty-color-support.out @@ -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) From 2ca8186afd81ebf24b0a944d08856592533aaa45 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 12 Apr 2020 19:08:22 +0200 Subject: [PATCH 2/3] fixup! process: suggest --trace-warnings when printing warning --- lib/internal/process/warning.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 490de2f0caeec1..4434b715d508fc 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -81,7 +81,8 @@ function onWarning(warning) { } if (!trace && !traceWarningHelperShown) { const flag = isDeprecation ? '--trace-deprecation' : '--trace-warnings'; - msg += `\n(Use \`node ${flag} ...\` to show where the warning ` + + const argv0 = require('path').basename(process.argv0 || 'node'); + msg += `\n(Use \`${argv0} ${flag} ...\` to show where the warning ` + 'was created)'; traceWarningHelperShown = true; } From 6405a9a766f8de1183e2783949d5ab6c82b607f7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 12 Apr 2020 22:37:10 +0200 Subject: [PATCH 3/3] fixup! process: suggest --trace-warnings when printing warning --- lib/internal/process/warning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 4434b715d508fc..383bbd7e0fe79f 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -81,7 +81,7 @@ function onWarning(warning) { } if (!trace && !traceWarningHelperShown) { const flag = isDeprecation ? '--trace-deprecation' : '--trace-warnings'; - const argv0 = require('path').basename(process.argv0 || 'node'); + const argv0 = require('path').basename(process.argv0 || 'node', '.exe'); msg += `\n(Use \`${argv0} ${flag} ...\` to show where the warning ` + 'was created)'; traceWarningHelperShown = true;