import { colors, htmlEscape, wordWrap } from "./chunk-4L7RY2JA.js"; import { BaseComponent, publicDirURL } from "./chunk-PE3GG3TN.js"; // src/templates/error_info/main.ts var ERROR_ICON_SVG = ``; var HINT_ICON_SVG = ``; var COPY_ICON_SVG = ``; function buildErrorWithStacktrace(error) { const cwd = process.cwd(); const lines = []; lines.push(`${error.name}: ${error.message}`); if (error.hint) { lines.push(`Hint: ${error.hint.replace(/(<([^>]+)>)/gi, "")}`); } if (error.frames.length > 0) { lines.push(""); lines.push("Stack trace:"); for (const frame of error.frames) { const fileName = frame.fileName?.replace(`${cwd}/`, "") || ""; const func = frame.functionName ? `at ${frame.functionName} ` : "at "; lines.push(` ${func}(${fileName}:${frame.lineNumber}:${frame.columnNumber})`); } } return lines.join("\n"); } function htmlAttributeEscape(value) { return value.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(//g, ">"); } var ErrorInfo = class extends BaseComponent { cssFile = new URL("./error_info/style.css", publicDirURL); scriptFile = new URL("./error_info/script.js", publicDirURL); /** * The toHTML method is used to output the HTML for the * web view */ async toHTML(props) { const stacktraceText = buildErrorWithStacktrace(props.error); return `

${htmlEscape(props.error.name)}

${htmlEscape(props.title)}

${ERROR_ICON_SVG} ${htmlEscape(props.error.message)}

${props.error.hint ? `
${HINT_ICON_SVG} ${props.error.hint}
` : ""}
`; } /** * The toANSI method is used to output the text for the console */ async toANSI(props) { const errorMessage = colors.red( `\u2139 ${wordWrap(`${props.error.name}: ${props.error.message}`, { width: process.stdout.columns, indent: " ", newLine: "\n", escape: (value) => value })}` ); const hint = props.error.hint ? ` ${colors.blue("\u25C9")} ${colors.dim().italic( wordWrap(props.error.hint.replace(/(<([^>]+)>)/gi, ""), { width: process.stdout.columns, indent: " ", newLine: "\n", escape: (value) => value }) )}` : ""; return `${errorMessage}${hint}`; } }; export { ErrorInfo };