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

Function emitWarning

lib/internal/process/warning.js:138–181  ·  view source on GitHub ↗
(warning, type, code, ctor)

Source from the content-addressed store, hash-verified

136// process.emitWarning(str[, type[, code]][, ctor])
137// process.emitWarning(str[, options])
138function emitWarning(warning, type, code, ctor) {
139 // Fast path to avoid memory allocation,
140 // this doesn't eliminate the other if a few lines below
141 if (process.noDeprecation && type === 'DeprecationWarning') {
142 return;
143 }
144 let detail;
145 if (type !== null && typeof type === 'object' && !ArrayIsArray(type)) {
146 ctor = type.ctor;
147 code = type.code;
148 if (typeof type.detail === 'string')
149 detail = type.detail;
150 type = type.type || 'Warning';
151 } else if (typeof type === 'function') {
152 ctor = type;
153 code = undefined;
154 type = 'Warning';
155 }
156 if (type !== undefined)
157 validateString(type, 'type');
158 if (typeof code === 'function') {
159 ctor = code;
160 code = undefined;
161 } else if (code !== undefined) {
162 validateString(code, 'code');
163 }
164 if (typeof warning === 'string') {
165 warning = createWarningObject(warning, type, code, ctor, detail);
166 } else if (!(warning instanceof Error)) {
167 throw new ERR_INVALID_ARG_TYPE('warning', ['Error', 'string'], warning);
168 }
169 if (warning.name === 'DeprecationWarning') {
170 if (process.noDeprecation)
171 return;
172 if (process.throwDeprecation) {
173 // Delay throwing the error to guarantee that all former warnings were
174 // properly logged.
175 return process.nextTick(() => {
176 throw warning;
177 });
178 }
179 }
180 process.nextTick(doEmitWarning, warning);
181}
182
183function emitWarningSync(warning, type, code, ctor) {
184 process.emit('warning', createWarningObject(warning, type, code, ctor));

Callers 1

Calls 1

createWarningObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…