Skip to content
Closed
Changes from all 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
27 changes: 21 additions & 6 deletions lib/internal/process/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down