UNPKG

@flanksource/clicky-ui

Version:

Flanksource Clicky UI — React component library built on shadcn/ui with light/dark and density theming.

88 lines (87 loc) 2.76 kB
const frameRe = /^\s*at\s+([\w$.]+)\.([\w$<>]+)\(([^)]+)\)/; const headerRe = /^([\w.$]+(?:Exception|Error|Throwable))(?::\s*(.*))?$/; const continuationRe = /^\.\.\.\s+\d+\s+more$/; const runtimePrefixes = ["java.", "javax.", "sun.", "jdk.", "com.sun.", "oracle.jrockit."]; function parseJavaStackTrace(input) { const out = { causedBy: [], frames: [], language: "java" }; if (!input || !input.trim()) return out; const headerLines = []; for (const raw of input.split("\n")) { const trimmed = raw.trim(); if (!trimmed) continue; if (continuationRe.test(trimmed)) continue; const frameMatch = frameRe.exec(raw); if (frameMatch && frameMatch[1] && frameMatch[2] && frameMatch[3] !== void 0) { out.frames.push(buildFrame(frameMatch[1], frameMatch[2], frameMatch[3])); continue; } if (trimmed.startsWith("Caused by:")) { out.causedBy.push(trimmed.slice("Caused by:".length).trim()); continue; } if (trimmed.startsWith("Internal Exception:")) { out.causedBy.push(trimmed.slice("Internal Exception:".length).trim()); continue; } if (!out.exceptionClass) { const headerMatch = headerRe.exec(trimmed); if (headerMatch && headerMatch[1]) { out.exceptionClass = headerMatch[1]; if (headerMatch[2]) out.message = headerMatch[2]; continue; } } headerLines.push(trimmed); } if (!out.message && headerLines.length > 0) { out.message = headerLines.join(" "); } return out; } function buildFrame(cls, method, locRaw) { const loc = locRaw.trim(); let file; let line; let nativeMethod = false; if (loc === "Native Method") { nativeMethod = true; } else if (loc !== "Unknown Source") { const cleaned = (loc.split(" ~[")[0] ?? loc).trim(); const i = cleaned.lastIndexOf(":"); if (i >= 0) { file = cleaned.slice(0, i); const n = Number(cleaned.slice(i + 1)); if (Number.isFinite(n)) line = n; } else { file = cleaned; } } const functionName = `${cls}.${method}`; const location = file ? line ? `${file}:${line}` : file : nativeMethod ? "Native Method" : void 0; const frame = { functionName, displayName: shortDisplay(cls, method), kind: "frame", runtime: runtimePrefixes.some((p) => cls.startsWith(p)), nativeMethod, class: cls, method }; if (file !== void 0) frame.file = file; if (line !== void 0) frame.line = line; if (location !== void 0) frame.location = location; return frame; } function shortDisplay(cls, method) { const parts = cls.split("."); const last = parts[parts.length - 1] ?? cls; return `${last}.${method}`; } export { parseJavaStackTrace }; //# sourceMappingURL=stacktrace-parse.js.map