MCPcopy Index your code
hub / github.com/nodejs/node / onWarning

Function onWarning

lib/internal/process/warning.js:90–133  ·  view source on GitHub ↗
(warning)

Source from the content-addressed store, hash-verified

88let disableWarningSet;
89
90function onWarning(warning) {
91 if (!disableWarningSet) {
92 disableWarningSet = new SafeSet();
93 const disableWarningValues = getOptionValue('--disable-warning');
94 for (let i = 0; i < disableWarningValues.length; i++) {
95 disableWarningSet.add(disableWarningValues[i]);
96 }
97 }
98 if ((warning?.code && disableWarningSet.has(warning.code)) ||
99 (warning?.name && disableWarningSet.has(warning.name))) return;
100
101 if (!(warning instanceof Error)) return;
102
103 const isDeprecation = warning.name === 'DeprecationWarning';
104 if (isDeprecation && process.noDeprecation) return;
105 const trace = process.traceProcessWarnings ||
106 (isDeprecation && process.traceDeprecation);
107 let msg = `(${process.release.name}:${process.pid}) `;
108 if (warning.code)
109 msg += `[${warning.code}] `;
110 if (trace && warning.stack) {
111 msg += `${warning.stack}`;
112 } else {
113 msg +=
114 typeof warning.toString === 'function' ?
115 `${warning.toString()}` :
116 ErrorPrototypeToString(warning);
117 }
118 if (typeof warning.detail === 'string') {
119 msg += `\n${warning.detail}`;
120 }
121 if (!trace && !traceWarningHelperShown) {
122 const flag = isDeprecation ? '--trace-deprecation' : '--trace-warnings';
123 const argv0 = require('path').basename(process.argv0 || 'node', '.exe');
124 msg += `\n(Use \`${argv0} ${flag} ...\` to show where the warning ` +
125 'was created)';
126 traceWarningHelperShown = true;
127 }
128 const warningFile = lazyOption();
129 if (warningFile) {
130 return writeToFile(msg);
131 }
132 writeOut(msg);
133}
134
135// process.emitWarning(error)
136// process.emitWarning(str[, type[, code]][, ctor])

Callers

nothing calls this directly

Calls 8

getOptionValueFunction · 0.85
lazyOptionFunction · 0.85
writeToFileFunction · 0.85
writeOutFunction · 0.85
addMethod · 0.65
hasMethod · 0.65
requireFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…