diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 383bbd7e0fe79f..f2879ad8d4234e 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -58,6 +58,17 @@ function doEmitWarning(warning) { return () => process.emit('warning', warning); } +function hideInternalStacks(stacks) { + const newStack = []; + for (const stack of stacks.split('\n')) { + if (/\(internal\/.+\)$/.test(stack)) { + continue; + } + newStack.push(stack); + } + return newStack.join('\n'); +} + let traceWarningHelperShown = false; function onWarning(warning) { if (!(warning instanceof Error)) return; @@ -79,12 +90,16 @@ 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; + if (!traceWarningHelperShown) { + if (!trace) { + 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; + } else { + msg = hideInternalStacks(msg); + } } const warningFile = lazyOption(); if (warningFile) {