MCPcopy
hub / github.com/webpack/webpack-dev-server / formatProblem

Function formatProblem

client-src/overlay.js:400–434  ·  view source on GitHub ↗
(type, item)

Source from the content-addressed store, hash-verified

398 * @returns {{ header: string, body: string }} formatted problem
399 */
400const formatProblem = (type, item) => {
401 let header = type === "warning" ? "WARNING" : "ERROR";
402 let body = "";
403
404 if (typeof item === "string") {
405 body += item;
406 } else {
407 const file = item.file || "";
408 const moduleName = item.moduleName
409 ? item.moduleName.indexOf("!") !== -1
410 ? `${item.moduleName.replace(/^(\s|\S)*!/, "")} (${item.moduleName})`
411 : `${item.moduleName}`
412 : "";
413 const loc = item.loc;
414
415 header += `${
416 moduleName || file
417 ? ` in ${
418 moduleName ? `${moduleName}${file ? ` (${file})` : ""}` : file
419 }${loc ? ` ${loc}` : ""}`
420 : ""
421 }`;
422 body += item.message || "";
423 }
424
425 if (typeof item !== "string" && Array.isArray(item.stack)) {
426 item.stack.forEach((stack) => {
427 if (typeof stack === "string") {
428 body += `\r\n${stack}`;
429 }
430 });
431 }
432
433 return { header, body };
434};
435
436/**
437 * @typedef {object} CreateOverlayOptions

Callers 3

warningsFunction · 0.90
errorsFunction · 0.90
showFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…