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

module: hide internal stack when emitCircularRequireWarning #32991

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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