UNPKG

@visulima/error

Version:

Error with more than just a message, stacktrace parsing.

25 lines (23 loc) 901 B
const formatStackFrameLine = (frame) => { const method = frame.methodName && frame.methodName !== "<unknown>" ? `${frame.methodName} ` : ""; const file = frame.file ?? "<unknown>"; const line = frame.line ?? 0; const column = frame.column ?? 0; if (method.trim()) { return ` at ${method}(${file}:${line}:${column})`; } return ` at ${file}:${line}:${column}`; }; const formatStacktrace = (frames, options) => { const lines = []; if (options?.header && (options.header.name || options.header.message)) { const headerName = String(options.header.name || "Error"); const headerMessage = String(options.header.message || ""); lines.push(`${headerName}${headerMessage ? ": " : ""}${headerMessage}`); } for (const frame of frames) { lines.push(formatStackFrameLine(frame)); } return lines.join("\n"); }; export { formatStackFrameLine, formatStacktrace };