@adea-ai/ui 0.142.2 → 0.142.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/composites/stack-trace/parse-stack-trace.d.ts.map +1 -1
- package/dist/components/composites/stack-trace/parse-stack-trace.js +71 -9
- package/dist/components/composites/stack-trace/parse-stack-trace.js.map +1 -1
- package/dist/r/src/components/composites/stack-trace/parse-stack-trace.ts +78 -8
- package/package.json +1 -1
- package/src/components/composites/stack-trace/parse-stack-trace.ts +78 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-stack-trace.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/stack-trace/parse-stack-trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAAA;AACtE,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;AAEnE,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,cAAc,CAAA;IACpB,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,iFAAiF;IACjF,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,UAAU,GAClB,QAAQ,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC,GAC9C,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,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AEF;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,YAAY,CAwBd"}
|
|
@@ -25,6 +25,31 @@ function splitLocation(location) {
|
|
|
25
25
|
line: last.value
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Split the pre-1.78 Rust panic suffix `'message', location`. The message may
|
|
30
|
+
* contain `', ` itself, and the greedy pattern this replaces took the last
|
|
31
|
+
* occurrence with a non-space behind it — this scan keeps that last-wins
|
|
32
|
+
* answer, in one pass, so a message repeating the marker stays linear.
|
|
33
|
+
*/
|
|
34
|
+
function splitRustOldPanic(after) {
|
|
35
|
+
if (/[\n\r\u2028\u2029]/.test(after) || !after.startsWith("'")) return void 0;
|
|
36
|
+
let close;
|
|
37
|
+
let search = 1;
|
|
38
|
+
for (;;) {
|
|
39
|
+
const at = after.indexOf("', ", search);
|
|
40
|
+
if (at < 0) break;
|
|
41
|
+
search = at + 1;
|
|
42
|
+
const start = at + 3;
|
|
43
|
+
if (start >= after.length) continue;
|
|
44
|
+
if (/\s/.test(after[start])) continue;
|
|
45
|
+
close = at;
|
|
46
|
+
}
|
|
47
|
+
if (close === void 0) return void 0;
|
|
48
|
+
return {
|
|
49
|
+
message: after.slice(1, close),
|
|
50
|
+
location: after.slice(close + 3)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
28
53
|
var FILE_LIKE = /[\\/]|\.[A-Za-z0-9]{1,6}$/;
|
|
29
54
|
var URL_LIKE = /^node:/i;
|
|
30
55
|
/** Whether a V8 location is a place in a file rather than a runtime annotation. */
|
|
@@ -66,17 +91,54 @@ function parseV8(trimmed) {
|
|
|
66
91
|
}
|
|
67
92
|
return draft;
|
|
68
93
|
}
|
|
69
|
-
var
|
|
94
|
+
var PYTHON_PREFIX = "File \"";
|
|
95
|
+
var PYTHON_LINE = "\", line ";
|
|
96
|
+
var PYTHON_IN = ", in ";
|
|
97
|
+
/** Whether a character is an ASCII digit, as `\d` was in the pattern this replaced. */
|
|
98
|
+
function isDigit(code) {
|
|
99
|
+
return code >= 48 && code <= 57;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Read a Python frame: `File "<file>", line <n>[, in <fn>]`.
|
|
103
|
+
*
|
|
104
|
+
* Scanned, not matched. A line repeating the frame shape many times must still
|
|
105
|
+
* cost one pass, so the closing `", line ` is found by walking its candidates
|
|
106
|
+
* left to right. The last valid candidate wins — what the greedy pattern this
|
|
107
|
+
* replaces would have settled on — so a file path containing a quote still
|
|
108
|
+
* parses exactly as it always did.
|
|
109
|
+
*/
|
|
70
110
|
function parsePython(trimmed) {
|
|
71
|
-
|
|
72
|
-
|
|
111
|
+
if (/[\n\r\u2028\u2029]/.test(trimmed) || !trimmed.startsWith(PYTHON_PREFIX)) return void 0;
|
|
112
|
+
let close;
|
|
113
|
+
let digits = 0;
|
|
114
|
+
let rest = 0;
|
|
115
|
+
let hasIn = false;
|
|
116
|
+
let search = 6;
|
|
117
|
+
for (;;) {
|
|
118
|
+
const at = trimmed.indexOf(PYTHON_LINE, search);
|
|
119
|
+
if (at < 0) break;
|
|
120
|
+
search = at + 1;
|
|
121
|
+
let end = at + 8;
|
|
122
|
+
const start = end;
|
|
123
|
+
while (end < trimmed.length && isDigit(trimmed.charCodeAt(end))) end += 1;
|
|
124
|
+
if (end === start) continue;
|
|
125
|
+
if (end < trimmed.length && !trimmed.startsWith(PYTHON_IN, end)) continue;
|
|
126
|
+
close = at;
|
|
127
|
+
digits = end - start;
|
|
128
|
+
rest = end;
|
|
129
|
+
hasIn = end < trimmed.length;
|
|
130
|
+
}
|
|
131
|
+
if (close === void 0) return void 0;
|
|
73
132
|
const draft = {
|
|
74
133
|
raw: trimmed,
|
|
75
134
|
format: "python",
|
|
76
|
-
file:
|
|
77
|
-
line: Number(
|
|
135
|
+
file: trimmed.slice(6, close),
|
|
136
|
+
line: Number(trimmed.slice(rest - digits, rest))
|
|
78
137
|
};
|
|
79
|
-
if (
|
|
138
|
+
if (hasIn) {
|
|
139
|
+
const fn = trimmed.slice(rest + 5);
|
|
140
|
+
if (fn) draft.function = fn;
|
|
141
|
+
}
|
|
80
142
|
return draft;
|
|
81
143
|
}
|
|
82
144
|
var RUST_FRAME = /^(\d+):\s+(?:0x[0-9a-fA-F]+ - )?(\S.*)$/;
|
|
@@ -239,13 +301,13 @@ function liftHeader(entries, format) {
|
|
|
239
301
|
if (at < 0) return void 0;
|
|
240
302
|
const type = first.slice(0, at).trim();
|
|
241
303
|
const after = first.slice(at + 4);
|
|
242
|
-
const old =
|
|
304
|
+
const old = splitRustOldPanic(after);
|
|
243
305
|
let consumed = 1;
|
|
244
306
|
let message;
|
|
245
307
|
let location;
|
|
246
308
|
if (old) {
|
|
247
|
-
message = old
|
|
248
|
-
location = old
|
|
309
|
+
message = old.message;
|
|
310
|
+
location = old.location;
|
|
249
311
|
} else {
|
|
250
312
|
location = after.replace(/:$/, "");
|
|
251
313
|
const body = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-stack-trace.js","names":[],"sources":["../../../../src/components/composites/stack-trace/parse-stack-trace.ts"],"sourcesContent":["/**\n * Stack traces, read without being trusted or trimmed.\n *\n * A trace is text a runtime wrote about itself, and every language writes it\n * differently. This parses the three a coding agent meets most — V8/Node\n * (`at fn (file:line:col)`), Python (`File \"x\", line N, in fn`) and Rust panic\n * backtraces (` 0: symbol` then `at file:line:col`) — into frames, and does\n * three things a formatter would not:\n *\n * - **It never hides a line.** Every input line ends up in `entries`, as a frame\n * or as text, in order. A line the parser does not recognise is text, and a\n * trace it recognises nothing in has `format: 'unknown'` and `frames: []`, so a\n * caller falls back to showing the raw string. The header (error type and\n * message) is lifted out of the entries only when it is unambiguous.\n * - **It makes no claim about whose code a frame is without evidence.** A frame\n * is a dependency when its path says so (`node_modules`, `site-packages`,\n * `.cargo/registry`), internal when it belongs to the runtime (`node:` URLs,\n * Python's frozen modules, Rust's `std`), and first-party otherwise. A host that\n * knows better passes `classify`.\n * - **It is bounded.** Lines over 4 000 characters are never run through a\n * pattern, and input past 10 000 lines is kept as one trailing text entry. Every\n * pattern is anchored and linear, so a hostile trace cannot make parsing slow.\n *\n * Parsing is line-oriented and each line is classified on its own, so a trace\n * that mixes formats (a Node process that shells out to Python) keeps both.\n */\n\nexport type StackFrameKind = 'first-party' | 'dependency' | 'internal'\nexport type StackTraceFormat = 'v8' | 'python' | 'rust' | 'unknown'\n\nexport type StackFrame = Readonly<{\n /** The line exactly as written, minus its line ending. */\n raw: string\n function?: string\n /** The path or URL as written. Undefined for `<anonymous>`, `native` and the like. */\n file?: string\n line?: number\n column?: number\n kind: StackFrameKind\n async?: true\n /** Lines the runtime printed beneath the frame, such as Python's source line. */\n detail?: readonly string[]\n}>\n\nexport type StackEntry =\n | Readonly<{ type: 'frame'; frame: StackFrame }>\n | Readonly<{ type: 'text'; text: string }>\n\nexport type StackTraceHeader = Readonly<{\n /** `TypeError`, `ValueError`, `thread 'main' panicked`. */\n type?: string\n message: string\n /** Where a Rust panic says it happened. */\n location?: string\n}>\n\nexport type ParsedStackTrace = Readonly<{\n format: StackTraceFormat\n header?: StackTraceHeader\n /** Everything that is not the header, in order. */\n entries: readonly StackEntry[]\n frames: readonly StackFrame[]\n}>\n\nexport type ParseStackTraceOptions = {\n /** Override the built-in first-party/dependency/internal guess for a frame. */\n classify?: (frame: StackFrame) => StackFrameKind | undefined\n}\n\nexport const STACK_MAX_LINES = 10_000\nconst LINE_PATTERN_LIMIT = 4000\n\ntype Draft = {\n raw: string\n function?: string\n file?: string\n line?: number\n column?: number\n async?: true\n detail?: string[]\n format: 'v8' | 'python' | 'rust'\n}\n\nfunction trailingNumber(value: string): { value: number; rest: string } | undefined {\n let i = value.length\n while (i > 0 && value.charCodeAt(i - 1) >= 48 && value.charCodeAt(i - 1) <= 57) i -= 1\n if (i === value.length || i === 0 || value[i - 1] !== ':' || value.length - i > 9)\n return undefined\n return { value: Number(value.slice(i)), rest: value.slice(0, i - 1) }\n}\n\n/** Split `path:line:col` from the right, so a Windows drive or a URL port stays in the path. */\nexport function splitLocation(location: string): { file: string; line?: number; column?: number } {\n const last = trailingNumber(location)\n if (!last || last.rest === '') return { file: location }\n const before = trailingNumber(last.rest)\n if (before && before.rest !== '') {\n return { file: before.rest, line: before.value, column: last.value }\n }\n return { file: last.rest, line: last.value }\n}\n\nconst FILE_LIKE = /[\\\\/]|\\.[A-Za-z0-9]{1,6}$/\nconst URL_LIKE = /^node:/i\n\n/** Whether a V8 location is a place in a file rather than a runtime annotation. */\nfunction v8Location(location: string): Partial<Draft> | undefined {\n if (location === '<anonymous>' || location === 'native' || /^index \\d+$/.test(location)) {\n return {}\n }\n if (location.startsWith('eval at ')) return {}\n const split = splitLocation(location)\n if (split.line !== undefined || FILE_LIKE.test(split.file) || URL_LIKE.test(split.file)) {\n return { file: split.file, line: split.line, column: split.column }\n }\n return undefined\n}\n\nfunction parseV8(trimmed: string): Draft | undefined {\n if (!trimmed.startsWith('at ')) return undefined\n const rest = trimmed.slice(3)\n if (rest === '') return undefined\n\n let fn: string | undefined\n let location: string\n if (rest.endsWith(')') && rest.includes(' (')) {\n const open = rest.indexOf(' (')\n fn = rest.slice(0, open)\n location = rest.slice(open + 2, -1)\n } else {\n location = rest\n }\n const parsed = v8Location(location)\n if (!parsed) return undefined\n // Without parentheses the whole remainder was the location, and it must carry\n // a line or a path — otherwise \"at the end of the day\" would be a frame.\n if (\n fn === undefined &&\n parsed.file === undefined &&\n location !== '<anonymous>' &&\n location !== 'native'\n ) {\n return undefined\n }\n\n const draft: Draft = { raw: trimmed, format: 'v8', ...parsed }\n if (fn !== undefined) {\n if (fn.startsWith('async ')) {\n draft.async = true\n fn = fn.slice(6)\n }\n if (fn !== '') draft.function = fn\n }\n return draft\n}\n\nconst PYTHON_FRAME = /^File \"(.*)\", line (\\d+)(?:, in (.*))?$/\n\nfunction parsePython(trimmed: string): Draft | undefined {\n const match = PYTHON_FRAME.exec(trimmed)\n if (!match) return undefined\n const draft: Draft = { raw: trimmed, format: 'python', file: match[1], line: Number(match[2]) }\n if (match[3]) draft.function = match[3]\n return draft\n}\n\nconst RUST_FRAME = /^(\\d+):\\s+(?:0x[0-9a-fA-F]+ - )?(\\S.*)$/\nconst RUST_LOCATION = /^at\\s+(\\S.*)$/\n\nfunction parseRustFrame(trimmed: string, rustContext: boolean): Draft | undefined {\n const match = RUST_FRAME.exec(trimmed)\n if (!match) return undefined\n const symbol = match[2]!\n if (!rustContext && !symbol.includes('::')) return undefined\n return { raw: trimmed, format: 'rust', function: symbol }\n}\n\nconst INTERNAL_RUST_SYMBOLS =\n /^(?:std|core|alloc)::|^<?(?:\\w+ as )?(?:std|core|alloc)::|^(?:rust_begin_unwind|rust_panic|__rust_|_start$|__libc_|_main$)/\n\n/** The built-in guess at whose code a frame is. See the module comment. */\nexport function classifyFrame(\n frame: Omit<StackFrame, 'kind'>,\n format: StackTraceFormat\n): StackFrameKind {\n const file = frame.file?.replaceAll('\\\\', '/')\n if (format === 'rust') {\n if (file !== undefined) {\n if (file.startsWith('/rustc/') || /\\/library\\/(?:std|core|alloc)\\//.test(file))\n return 'internal'\n if (/\\/\\.cargo\\/(?:registry|git)\\/|\\/registry\\/src\\//.test(file)) return 'dependency'\n return 'first-party'\n }\n return frame.function !== undefined && INTERNAL_RUST_SYMBOLS.test(frame.function)\n ? 'internal'\n : 'first-party'\n }\n if (file === undefined) return 'internal'\n if (format === 'python') {\n if (/\\/(?:site|dist)-packages\\//.test(file)) return 'dependency'\n if (\n file.startsWith('<') ||\n /\\/lib\\/python\\d/i.test(file) ||\n /\\/python\\d[\\d.]*\\/lib\\//i.test(file)\n ) {\n return 'internal'\n }\n return 'first-party'\n }\n if (file.startsWith('node:') || file.startsWith('internal/') || file.startsWith('wasm://')) {\n return 'internal'\n }\n if (file.includes('/node_modules/') || file.startsWith('node_modules/')) return 'dependency'\n return 'first-party'\n}\n\nfunction finishFrame(draft: Draft, options: ParseStackTraceOptions | undefined): StackFrame {\n const { format, detail, ...base } = draft\n const shape: Omit<StackFrame, 'kind'> = detail && detail.length > 0 ? { ...base, detail } : base\n // Classified by the frame's own format, so a mixed trace keeps both languages' rules.\n const guess = classifyFrame(shape, format)\n const override = options?.classify?.({ ...shape, kind: guess })\n return { ...shape, kind: override ?? guess }\n}\n\nconst TYPE_AND_MESSAGE = /^([A-Za-z_$][\\w$.]*)(?::\\s?([\\s\\S]*))?$/\n\nfunction splitTypeAndMessage(lines: readonly string[]): StackTraceHeader {\n const first = lines[0] ?? ''\n const match = TYPE_AND_MESSAGE.exec(first)\n const tail = lines.slice(1)\n if (!match) return { message: lines.join('\\n') }\n const message = [match[2] ?? '', ...tail].join('\\n').replace(/^\\n+/, '')\n return { type: match[1], message }\n}\n\n/** Parse a stack trace. Never throws, and every input line appears in the result. */\nexport function parseStackTrace(text: string, options?: ParseStackTraceOptions): ParsedStackTrace {\n const rawLines = text.split('\\n')\n const overflow = rawLines.length > STACK_MAX_LINES ? rawLines.splice(STACK_MAX_LINES) : []\n const rustContext = /panicked at|stack backtrace|RUST_BACKTRACE/.test(text.slice(0, 200_000))\n\n type Item = { type: 'text'; text: string } | { type: 'frame'; draft: Draft }\n const items: Item[] = []\n let python: Draft | undefined\n let rust: Draft | undefined\n\n for (const original of rawLines) {\n const line = original.endsWith('\\r') ? original.slice(0, -1) : original\n const trimmed = line.trim()\n\n if (line.length > LINE_PATTERN_LIMIT || trimmed === '') {\n python = rust = undefined\n items.push({ type: 'text', text: line })\n continue\n }\n\n // Python prints the offending source line, indented, under its frame.\n if (python && /^\\s/.test(line) && !trimmed.startsWith('File \"')) {\n ;(python.detail ??= []).push(line)\n continue\n }\n\n if (rust && rust.file === undefined && RUST_LOCATION.test(trimmed)) {\n const split = splitLocation(RUST_LOCATION.exec(trimmed)![1]!)\n rust.file = split.file\n rust.line = split.line\n rust.column = split.column\n rust.raw = `${rust.raw}\\n${line}`\n continue\n }\n\n const draft = parsePython(trimmed) ?? parseRustFrame(trimmed, rustContext) ?? parseV8(trimmed)\n python = draft?.format === 'python' ? draft : undefined\n rust = draft?.format === 'rust' ? draft : undefined\n if (draft) items.push({ type: 'frame', draft })\n else items.push({ type: 'text', text: line })\n }\n if (overflow.length > 0) items.push({ type: 'text', text: overflow.join('\\n') })\n\n const counts = { v8: 0, python: 0, rust: 0 }\n for (const item of items) if (item.type === 'frame') counts[item.draft.format] += 1\n const total = counts.v8 + counts.python + counts.rust\n const format: StackTraceFormat =\n total === 0\n ? 'unknown'\n : counts.python >= counts.v8 && counts.python >= counts.rust\n ? 'python'\n : counts.rust >= counts.v8\n ? 'rust'\n : 'v8'\n\n const entries: StackEntry[] = items.map((item) =>\n item.type === 'text' ? item : { type: 'frame', frame: finishFrame(item.draft, options) }\n )\n\n if (format === 'unknown') return { format, entries, frames: [] }\n\n const header = liftHeader(entries, format)\n const frames = entries.flatMap((entry) => (entry.type === 'frame' ? [entry.frame] : []))\n return { format, ...(header && { header }), entries, frames }\n}\n\n/**\n * Take the header out of the entries it came from. V8 and Rust print it before\n * the frames; Python prints it after. The lifted lines are removed so they are\n * drawn once, as the header, and nothing else is touched.\n */\nfunction liftHeader(entries: StackEntry[], format: StackTraceFormat): StackTraceHeader | undefined {\n const firstFrame = entries.findIndex((entry) => entry.type === 'frame')\n\n if (format === 'python') {\n let last = entries.length - 1\n while (last >= 0 && (entries[last]!.type !== 'text' || isBlank(entries[last]!))) last -= 1\n let lastFrame = entries.length - 1\n while (lastFrame >= 0 && entries[lastFrame]!.type !== 'frame') lastFrame -= 1\n const entry = entries[last]\n // Only a line shaped like `Type: message` is taken as the header; anything\n // else after the last frame (`[Previous line repeated …]`) stays where it is.\n if (\n !entry ||\n entry.type !== 'text' ||\n last < lastFrame ||\n /^\\s/.test(entry.text) ||\n !TYPE_AND_MESSAGE.test(entry.text.trim())\n ) {\n return undefined\n }\n entries.splice(last, 1)\n return splitTypeAndMessage([entry.text.trim()])\n }\n\n if (format === 'rust') {\n const panicAt = entries.findIndex(\n (entry, index) =>\n index < firstFrame && entry.type === 'text' && /panicked at/.test(entry.text)\n )\n if (panicAt < 0) return undefined\n const first = (entries[panicAt] as { text: string }).text.trim()\n const at = first.indexOf(' at ')\n if (at < 0) return undefined\n const type = first.slice(0, at).trim()\n const after = first.slice(at + 4)\n const old = /^'(.*)', (\\S.*)$/.exec(after)\n let consumed = 1\n let message: string\n let location: string | undefined\n if (old) {\n message = old[1]!\n location = old[2]\n } else {\n location = after.replace(/:$/, '')\n const body: string[] = []\n for (let i = panicAt + 1; i < firstFrame; i += 1) {\n const entry = entries[i]!\n if (\n entry.type !== 'text' ||\n isBlank(entry) ||\n /^(?:note:|stack backtrace:)/.test(entry.text.trim())\n )\n break\n body.push(entry.text)\n consumed += 1\n }\n message = body.join('\\n')\n }\n entries.splice(panicAt, consumed)\n return { type, message, ...(location && { location }) }\n }\n\n // V8: the block of non-blank lines directly above the first frame. Anything\n // above a blank line — Node prints the source line that threw — stays as text.\n if (firstFrame <= 0) return undefined\n let start = firstFrame\n while (start > 0 && entries[start - 1]!.type === 'text' && !isBlank(entries[start - 1]!))\n start -= 1\n if (start === firstFrame) return undefined\n const lines = entries.slice(start, firstFrame).map((entry) => (entry as { text: string }).text)\n entries.splice(start, firstFrame - start)\n return splitTypeAndMessage(lines)\n}\n\nfunction isBlank(entry: StackEntry): boolean {\n return entry.type === 'text' && entry.text.trim() === ''\n}\n\n// ---------------------------------------------------------------------------\n// Grouping\n// ---------------------------------------------------------------------------\n\nexport type StackBlock =\n | Readonly<{ type: 'frame'; frame: StackFrame }>\n | Readonly<{ type: 'text'; text: string }>\n | Readonly<{ type: 'group'; frames: readonly StackFrame[] }>\n\n/**\n * Fold runs of dependency and runtime frames into groups, so a trace reads as\n * the code the reader owns with the framework's frames one click away.\n *\n * A run of one stays a frame — a disclosure around a single line costs more than\n * it saves. When there is no first-party frame at all nothing is grouped:\n * collapsing everything would hide the entire trace behind a button, which is the\n * opposite of what a reader who owns none of the frames needs.\n */\nexport function groupStackEntries(\n entries: readonly StackEntry[],\n collapse = true\n): readonly StackBlock[] {\n const hasFirstParty = entries.some(\n (entry) => entry.type === 'frame' && entry.frame.kind === 'first-party'\n )\n if (!collapse || !hasFirstParty) return entries\n\n const blocks: StackBlock[] = []\n let run: StackFrame[] = []\n const flush = () => {\n if (run.length >= 2) blocks.push({ type: 'group', frames: run })\n else for (const frame of run) blocks.push({ type: 'frame', frame })\n run = []\n }\n for (const entry of entries) {\n if (entry.type === 'frame' && entry.frame.kind !== 'first-party') {\n run.push(entry.frame)\n continue\n }\n flush()\n blocks.push(entry)\n }\n flush()\n return blocks\n}\n\nconst framesNoun = (count: number, word: string) =>\n `${count.toLocaleString()} ${word} ${count === 1 ? 'frame' : 'frames'}`\n\n/** What a collapsed group says it holds. */\nexport function describeFrameGroup(frames: readonly StackFrame[]): string {\n const count = frames.length\n const dependency = frames.filter((frame) => frame.kind === 'dependency').length\n if (dependency === count) return framesNoun(count, 'dependency')\n if (dependency === 0) return framesNoun(count, 'runtime')\n return `${count.toLocaleString()} dependency and runtime frames`\n}\n\n/** `file:line:col`, with whichever parts the frame has. */\nexport function frameLocation(frame: StackFrame): string | undefined {\n if (frame.file === undefined) return undefined\n const column = frame.column === undefined ? '' : `:${frame.column}`\n const line = frame.line === undefined ? '' : `:${frame.line}`\n return `${frame.file}${line}${line ? column : ''}`\n}\n\nconst LEADING_SPACE = /^[ \\t]*/\n\n/** Remove the indentation every non-blank line shares, so a source snippet sits flush. */\nexport function dedentLines(lines: readonly string[]): string[] {\n let indent = Infinity\n for (const line of lines) {\n if (line.trim() !== '') indent = Math.min(indent, LEADING_SPACE.exec(line)![0].length)\n }\n if (indent === Infinity) return [...lines]\n return lines.map((line) => line.slice(Math.min(indent, LEADING_SPACE.exec(line)![0].length)))\n}\n\nexport type BoundedLines = Readonly<{\n lines: string[]\n /** Lines beyond the bound that are not in `lines` at all. */\n omittedLines: number\n /** Characters beyond the bound, in omitted lines and in the cut end of the last shown line. */\n omittedChars: number\n}>\n\n/**\n * The first lines of `lines`, up to `maxLines` of them and `maxChars` characters\n * between them, with what was left out counted rather than dropped silently. It\n * visits the shown lines and adds up the length of the rest, so the cost does not\n * depend on how much text there is to omit.\n */\nexport function boundLines(\n lines: readonly string[],\n maxLines: number,\n maxChars: number\n): BoundedLines {\n const shown: string[] = []\n let chars = 0\n let index = 0\n let partial = 0\n while (index < lines.length && shown.length < maxLines) {\n const line = lines[index]!\n const room = maxChars - chars\n if (line.length <= room) {\n shown.push(line)\n chars += line.length\n index += 1\n continue\n }\n if (room > 0) {\n shown.push(line.slice(0, room))\n partial = line.length - room\n index += 1\n }\n break\n }\n let omittedChars = partial\n for (let rest = index; rest < lines.length; rest += 1) omittedChars += lines[rest]!.length\n return { lines: shown, omittedLines: lines.length - index, omittedChars }\n}\n"],"mappings":";AAqEA,IAAa,kBAAkB;AAC/B,IAAM,qBAAqB;AAa3B,SAAS,eAAe,OAA4D;CAClF,IAAI,IAAI,MAAM;CACd,OAAO,IAAI,KAAK,MAAM,WAAW,IAAI,CAAC,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC,KAAK,IAAI,KAAK;CACrF,IAAI,MAAM,MAAM,UAAU,MAAM,KAAK,MAAM,IAAI,OAAO,OAAO,MAAM,SAAS,IAAI,GAC9E,OAAO,KAAA;CACT,OAAO;EAAE,OAAO,OAAO,MAAM,MAAM,CAAC,CAAC;EAAG,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC;CAAE;AACtE;;AAGA,SAAgB,cAAc,UAAoE;CAChG,MAAM,OAAO,eAAe,QAAQ;CACpC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,EAAE,MAAM,SAAS;CACvD,MAAM,SAAS,eAAe,KAAK,IAAI;CACvC,IAAI,UAAU,OAAO,SAAS,IAC5B,OAAO;EAAE,MAAM,OAAO;EAAM,MAAM,OAAO;EAAO,QAAQ,KAAK;CAAM;CAErE,OAAO;EAAE,MAAM,KAAK;EA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OAAO,CAAC,GAAG,KAAK;CACzC,OAAO,MAAM,KAAK,SAAS,KAAK,MAAM,KAAK,IAAI,QAAQ,cAAc,KAAK,IAAI,CAAC,CAAE,EAAE,CAAC,MAAM,CAAC,CAAC;AAC9F;;;;;;;AAgBA,SAAgB,WACd,OACA,UACA,UACc;CACd,MAAM,QAAkB,CAAC;CACzB,IAAI,QAAQ;CACZ,IAAI,QAAQ;CACZ,IAAI,UAAU;CACd,OAAO,QAAQ,MAAM,UAAU,MAAM,SAAS,UAAU;EACtD,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,WAAW;EACxB,IAAI,KAAK,UAAU,MAAM;GACvB,MAAM,KAAK,IAAI;GACf,SAAS,KAAK;GACd,SAAS;GACT;EACF;EACA,IAAI,OAAO,GAAG;GACZ,MAAM,KAAK,KAAK,MAAM,GAAG,IAAI,CAAC;GAC9B,UAAU,KAAK,SAAS;GACxB,SAAS;EACX;EACA;CACF;CACA,IAAI,eAAe;CACnB,KAAK,IAAI,OAAO,OAAO,OAAO,MAAM,QAAQ,QAAQ,GAAG,gBAAgB,MAAM,KAAK,CAAE;CACpF,OAAO;EAAE,OAAO;EAAO,cAAc,MAAM,SAAS;EAAO;CAAa;AAC1E"}
|
|
1
|
+
{"version":3,"file":"parse-stack-trace.js","names":[],"sources":["../../../../src/components/composites/stack-trace/parse-stack-trace.ts"],"sourcesContent":["/**\n * Stack traces, read without being trusted or trimmed.\n *\n * A trace is text a runtime wrote about itself, and every language writes it\n * differently. This parses the three a coding agent meets most — V8/Node\n * (`at fn (file:line:col)`), Python (`File \"x\", line N, in fn`) and Rust panic\n * backtraces (` 0: symbol` then `at file:line:col`) — into frames, and does\n * three things a formatter would not:\n *\n * - **It never hides a line.** Every input line ends up in `entries`, as a frame\n * or as text, in order. A line the parser does not recognise is text, and a\n * trace it recognises nothing in has `format: 'unknown'` and `frames: []`, so a\n * caller falls back to showing the raw string. The header (error type and\n * message) is lifted out of the entries only when it is unambiguous.\n * - **It makes no claim about whose code a frame is without evidence.** A frame\n * is a dependency when its path says so (`node_modules`, `site-packages`,\n * `.cargo/registry`), internal when it belongs to the runtime (`node:` URLs,\n * Python's frozen modules, Rust's `std`), and first-party otherwise. A host that\n * knows better passes `classify`.\n * - **It is bounded.** Lines over 4 000 characters are never run through a\n * pattern, and input past 10 000 lines is kept as one trailing text entry. Every\n * pattern is anchored and linear, so a hostile trace cannot make parsing slow.\n *\n * Parsing is line-oriented and each line is classified on its own, so a trace\n * that mixes formats (a Node process that shells out to Python) keeps both.\n */\n\nexport type StackFrameKind = 'first-party' | 'dependency' | 'internal'\nexport type StackTraceFormat = 'v8' | 'python' | 'rust' | 'unknown'\n\nexport type StackFrame = Readonly<{\n /** The line exactly as written, minus its line ending. */\n raw: string\n function?: string\n /** The path or URL as written. Undefined for `<anonymous>`, `native` and the like. */\n file?: string\n line?: number\n column?: number\n kind: StackFrameKind\n async?: true\n /** Lines the runtime printed beneath the frame, such as Python's source line. */\n detail?: readonly string[]\n}>\n\nexport type StackEntry =\n | Readonly<{ type: 'frame'; frame: StackFrame }>\n | Readonly<{ type: 'text'; text: string }>\n\nexport type StackTraceHeader = Readonly<{\n /** `TypeError`, `ValueError`, `thread 'main' panicked`. */\n type?: string\n message: string\n /** Where a Rust panic says it happened. */\n location?: string\n}>\n\nexport type ParsedStackTrace = Readonly<{\n format: StackTraceFormat\n header?: StackTraceHeader\n /** Everything that is not the header, in order. */\n entries: readonly StackEntry[]\n frames: readonly StackFrame[]\n}>\n\nexport type ParseStackTraceOptions = {\n /** Override the built-in first-party/dependency/internal guess for a frame. */\n classify?: (frame: StackFrame) => StackFrameKind | undefined\n}\n\nexport const STACK_MAX_LINES = 10_000\nconst LINE_PATTERN_LIMIT = 4000\n\ntype Draft = {\n raw: string\n function?: string\n file?: string\n line?: number\n column?: number\n async?: true\n detail?: string[]\n format: 'v8' | 'python' | 'rust'\n}\n\nfunction trailingNumber(value: string): { value: number; rest: string } | undefined {\n let i = value.length\n while (i > 0 && value.charCodeAt(i - 1) >= 48 && value.charCodeAt(i - 1) <= 57) i -= 1\n if (i === value.length || i === 0 || value[i - 1] !== ':' || value.length - i > 9)\n return undefined\n return { value: Number(value.slice(i)), rest: value.slice(0, i - 1) }\n}\n\n/** Split `path:line:col` from the right, so a Windows drive or a URL port stays in the path. */\nexport function splitLocation(location: string): { file: string; line?: number; column?: number } {\n const last = trailingNumber(location)\n if (!last || last.rest === '') return { file: location }\n const before = trailingNumber(last.rest)\n if (before && before.rest !== '') {\n return { file: before.rest, line: before.value, column: last.value }\n }\n return { file: last.rest, line: last.value }\n}\n\n/**\n * Split the pre-1.78 Rust panic suffix `'message', location`. The message may\n * contain `', ` itself, and the greedy pattern this replaces took the last\n * occurrence with a non-space behind it — this scan keeps that last-wins\n * answer, in one pass, so a message repeating the marker stays linear.\n */\nfunction splitRustOldPanic(after: string): { message: string; location: string } | undefined {\n // As in `parsePython`: no `.` in the old pattern could cross a line break.\n if (/[\\n\\r\\u2028\\u2029]/.test(after) || !after.startsWith(\"'\")) return undefined\n let close: number | undefined\n let search = 1\n for (;;) {\n const at = after.indexOf(\"', \", search)\n if (at < 0) break\n search = at + 1\n const start = at + 3\n if (start >= after.length) continue\n // Preserve ECMAScript \\S, including NBSP/BOM and Unicode space separators.\n if (/\\s/.test(after[start]!)) continue\n close = at\n }\n if (close === undefined) return undefined\n return { message: after.slice(1, close), location: after.slice(close + 3) }\n}\n\nconst FILE_LIKE = /[\\\\/]|\\.[A-Za-z0-9]{1,6}$/\nconst URL_LIKE = /^node:/i\n\n/** Whether a V8 location is a place in a file rather than a runtime annotation. */\nfunction v8Location(location: string): Partial<Draft> | undefined {\n if (location === '<anonymous>' || location === 'native' || /^index \\d+$/.test(location)) {\n return {}\n }\n if (location.startsWith('eval at ')) return {}\n const split = splitLocation(location)\n if (split.line !== undefined || FILE_LIKE.test(split.file) || URL_LIKE.test(split.file)) {\n return { file: split.file, line: split.line, column: split.column }\n }\n return undefined\n}\n\nfunction parseV8(trimmed: string): Draft | undefined {\n if (!trimmed.startsWith('at ')) return undefined\n const rest = trimmed.slice(3)\n if (rest === '') return undefined\n\n let fn: string | undefined\n let location: string\n if (rest.endsWith(')') && rest.includes(' (')) {\n const open = rest.indexOf(' (')\n fn = rest.slice(0, open)\n location = rest.slice(open + 2, -1)\n } else {\n location = rest\n }\n const parsed = v8Location(location)\n if (!parsed) return undefined\n // Without parentheses the whole remainder was the location, and it must carry\n // a line or a path — otherwise \"at the end of the day\" would be a frame.\n if (\n fn === undefined &&\n parsed.file === undefined &&\n location !== '<anonymous>' &&\n location !== 'native'\n ) {\n return undefined\n }\n\n const draft: Draft = { raw: trimmed, format: 'v8', ...parsed }\n if (fn !== undefined) {\n if (fn.startsWith('async ')) {\n draft.async = true\n fn = fn.slice(6)\n }\n if (fn !== '') draft.function = fn\n }\n return draft\n}\n\nconst PYTHON_PREFIX = 'File \"'\nconst PYTHON_LINE = '\", line '\nconst PYTHON_IN = ', in '\n\n/** Whether a character is an ASCII digit, as `\\d` was in the pattern this replaced. */\nfunction isDigit(code: number): boolean {\n return code >= 48 && code <= 57\n}\n\n/**\n * Read a Python frame: `File \"<file>\", line <n>[, in <fn>]`.\n *\n * Scanned, not matched. A line repeating the frame shape many times must still\n * cost one pass, so the closing `\", line ` is found by walking its candidates\n * left to right. The last valid candidate wins — what the greedy pattern this\n * replaces would have settled on — so a file path containing a quote still\n * parses exactly as it always did.\n */\nfunction parsePython(trimmed: string): Draft | undefined {\n // `.` never matches a line break, so the whole-line pattern this replaces\n // could not have matched a string containing one either.\n if (/[\\n\\r\\u2028\\u2029]/.test(trimmed) || !trimmed.startsWith(PYTHON_PREFIX)) return undefined\n let close: number | undefined\n let digits = 0\n let rest = 0\n let hasIn = false\n let search = PYTHON_PREFIX.length\n for (;;) {\n const at = trimmed.indexOf(PYTHON_LINE, search)\n if (at < 0) break\n search = at + 1\n let end = at + PYTHON_LINE.length\n const start = end\n while (end < trimmed.length && isDigit(trimmed.charCodeAt(end))) end += 1\n if (end === start) continue\n if (end < trimmed.length && !trimmed.startsWith(PYTHON_IN, end)) continue\n close = at\n digits = end - start\n rest = end\n hasIn = end < trimmed.length\n }\n if (close === undefined) return undefined\n const draft: Draft = {\n raw: trimmed,\n format: 'python',\n file: trimmed.slice(PYTHON_PREFIX.length, close),\n line: Number(trimmed.slice(rest - digits, rest)),\n }\n if (hasIn) {\n const fn = trimmed.slice(rest + PYTHON_IN.length)\n if (fn) draft.function = fn\n }\n return draft\n}\n\nconst RUST_FRAME = /^(\\d+):\\s+(?:0x[0-9a-fA-F]+ - )?(\\S.*)$/\nconst RUST_LOCATION = /^at\\s+(\\S.*)$/\n\nfunction parseRustFrame(trimmed: string, rustContext: boolean): Draft | undefined {\n const match = RUST_FRAME.exec(trimmed)\n if (!match) return undefined\n const symbol = match[2]!\n if (!rustContext && !symbol.includes('::')) return undefined\n return { raw: trimmed, format: 'rust', function: symbol }\n}\n\nconst INTERNAL_RUST_SYMBOLS =\n /^(?:std|core|alloc)::|^<?(?:\\w+ as )?(?:std|core|alloc)::|^(?:rust_begin_unwind|rust_panic|__rust_|_start$|__libc_|_main$)/\n\n/** The built-in guess at whose code a frame is. See the module comment. */\nexport function classifyFrame(\n frame: Omit<StackFrame, 'kind'>,\n format: StackTraceFormat\n): StackFrameKind {\n const file = frame.file?.replaceAll('\\\\', '/')\n if (format === 'rust') {\n if (file !== undefined) {\n if (file.startsWith('/rustc/') || /\\/library\\/(?:std|core|alloc)\\//.test(file))\n return 'internal'\n if (/\\/\\.cargo\\/(?:registry|git)\\/|\\/registry\\/src\\//.test(file)) return 'dependency'\n return 'first-party'\n }\n return frame.function !== undefined && INTERNAL_RUST_SYMBOLS.test(frame.function)\n ? 'internal'\n : 'first-party'\n }\n if (file === undefined) return 'internal'\n if (format === 'python') {\n if (/\\/(?:site|dist)-packages\\//.test(file)) return 'dependency'\n if (\n file.startsWith('<') ||\n /\\/lib\\/python\\d/i.test(file) ||\n /\\/python\\d[\\d.]*\\/lib\\//i.test(file)\n ) {\n return 'internal'\n }\n return 'first-party'\n }\n if (file.startsWith('node:') || file.startsWith('internal/') || file.startsWith('wasm://')) {\n return 'internal'\n }\n if (file.includes('/node_modules/') || file.startsWith('node_modules/')) return 'dependency'\n return 'first-party'\n}\n\nfunction finishFrame(draft: Draft, options: ParseStackTraceOptions | undefined): StackFrame {\n const { format, detail, ...base } = draft\n const shape: Omit<StackFrame, 'kind'> = detail && detail.length > 0 ? { ...base, detail } : base\n // Classified by the frame's own format, so a mixed trace keeps both languages' rules.\n const guess = classifyFrame(shape, format)\n const override = options?.classify?.({ ...shape, kind: guess })\n return { ...shape, kind: override ?? guess }\n}\n\nconst TYPE_AND_MESSAGE = /^([A-Za-z_$][\\w$.]*)(?::\\s?([\\s\\S]*))?$/\n\nfunction splitTypeAndMessage(lines: readonly string[]): StackTraceHeader {\n const first = lines[0] ?? ''\n const match = TYPE_AND_MESSAGE.exec(first)\n const tail = lines.slice(1)\n if (!match) return { message: lines.join('\\n') }\n const message = [match[2] ?? '', ...tail].join('\\n').replace(/^\\n+/, '')\n return { type: match[1], message }\n}\n\n/** Parse a stack trace. Never throws, and every input line appears in the result. */\nexport function parseStackTrace(text: string, options?: ParseStackTraceOptions): ParsedStackTrace {\n const rawLines = text.split('\\n')\n const overflow = rawLines.length > STACK_MAX_LINES ? rawLines.splice(STACK_MAX_LINES) : []\n const rustContext = /panicked at|stack backtrace|RUST_BACKTRACE/.test(text.slice(0, 200_000))\n\n type Item = { type: 'text'; text: string } | { type: 'frame'; draft: Draft }\n const items: Item[] = []\n let python: Draft | undefined\n let rust: Draft | undefined\n\n for (const original of rawLines) {\n const line = original.endsWith('\\r') ? original.slice(0, -1) : original\n const trimmed = line.trim()\n\n if (line.length > LINE_PATTERN_LIMIT || trimmed === '') {\n python = rust = undefined\n items.push({ type: 'text', text: line })\n continue\n }\n\n // Python prints the offending source line, indented, under its frame.\n if (python && /^\\s/.test(line) && !trimmed.startsWith('File \"')) {\n ;(python.detail ??= []).push(line)\n continue\n }\n\n if (rust && rust.file === undefined && RUST_LOCATION.test(trimmed)) {\n const split = splitLocation(RUST_LOCATION.exec(trimmed)![1]!)\n rust.file = split.file\n rust.line = split.line\n rust.column = split.column\n rust.raw = `${rust.raw}\\n${line}`\n continue\n }\n\n const draft = parsePython(trimmed) ?? parseRustFrame(trimmed, rustContext) ?? parseV8(trimmed)\n python = draft?.format === 'python' ? draft : undefined\n rust = draft?.format === 'rust' ? draft : undefined\n if (draft) items.push({ type: 'frame', draft })\n else items.push({ type: 'text', text: line })\n }\n if (overflow.length > 0) items.push({ type: 'text', text: overflow.join('\\n') })\n\n const counts = { v8: 0, python: 0, rust: 0 }\n for (const item of items) if (item.type === 'frame') counts[item.draft.format] += 1\n const total = counts.v8 + counts.python + counts.rust\n const format: StackTraceFormat =\n total === 0\n ? 'unknown'\n : counts.python >= counts.v8 && counts.python >= counts.rust\n ? 'python'\n : counts.rust >= counts.v8\n ? 'rust'\n : 'v8'\n\n const entries: StackEntry[] = items.map((item) =>\n item.type === 'text' ? item : { type: 'frame', frame: finishFrame(item.draft, options) }\n )\n\n if (format === 'unknown') return { format, entries, frames: [] }\n\n const header = liftHeader(entries, format)\n const frames = entries.flatMap((entry) => (entry.type === 'frame' ? [entry.frame] : []))\n return { format, ...(header && { header }), entries, frames }\n}\n\n/**\n * Take the header out of the entries it came from. V8 and Rust print it before\n * the frames; Python prints it after. The lifted lines are removed so they are\n * drawn once, as the header, and nothing else is touched.\n */\nfunction liftHeader(entries: StackEntry[], format: StackTraceFormat): StackTraceHeader | undefined {\n const firstFrame = entries.findIndex((entry) => entry.type === 'frame')\n\n if (format === 'python') {\n let last = entries.length - 1\n while (last >= 0 && (entries[last]!.type !== 'text' || isBlank(entries[last]!))) last -= 1\n let lastFrame = entries.length - 1\n while (lastFrame >= 0 && entries[lastFrame]!.type !== 'frame') lastFrame -= 1\n const entry = entries[last]\n // Only a line shaped like `Type: message` is taken as the header; anything\n // else after the last frame (`[Previous line repeated …]`) stays where it is.\n if (\n !entry ||\n entry.type !== 'text' ||\n last < lastFrame ||\n /^\\s/.test(entry.text) ||\n !TYPE_AND_MESSAGE.test(entry.text.trim())\n ) {\n return undefined\n }\n entries.splice(last, 1)\n return splitTypeAndMessage([entry.text.trim()])\n }\n\n if (format === 'rust') {\n const panicAt = entries.findIndex(\n (entry, index) =>\n index < firstFrame && entry.type === 'text' && /panicked at/.test(entry.text)\n )\n if (panicAt < 0) return undefined\n const first = (entries[panicAt] as { text: string }).text.trim()\n const at = first.indexOf(' at ')\n if (at < 0) return undefined\n const type = first.slice(0, at).trim()\n const after = first.slice(at + 4)\n const old = splitRustOldPanic(after)\n let consumed = 1\n let message: string\n let location: string | undefined\n if (old) {\n message = old.message\n location = old.location\n } else {\n location = after.replace(/:$/, '')\n const body: string[] = []\n for (let i = panicAt + 1; i < firstFrame; i += 1) {\n const entry = entries[i]!\n if (\n entry.type !== 'text' ||\n isBlank(entry) ||\n /^(?:note:|stack backtrace:)/.test(entry.text.trim())\n )\n break\n body.push(entry.text)\n consumed += 1\n }\n message = body.join('\\n')\n }\n entries.splice(panicAt, consumed)\n return { type, message, ...(location && { location }) }\n }\n\n // V8: the block of non-blank lines directly above the first frame. Anything\n // above a blank line — Node prints the source line that threw — stays as text.\n if (firstFrame <= 0) return undefined\n let start = firstFrame\n while (start > 0 && entries[start - 1]!.type === 'text' && !isBlank(entries[start - 1]!))\n start -= 1\n if (start === firstFrame) return undefined\n const lines = entries.slice(start, firstFrame).map((entry) => (entry as { text: string }).text)\n entries.splice(start, firstFrame - start)\n return splitTypeAndMessage(lines)\n}\n\nfunction isBlank(entry: StackEntry): boolean {\n return entry.type === 'text' && entry.text.trim() === ''\n}\n\n// ---------------------------------------------------------------------------\n// Grouping\n// ---------------------------------------------------------------------------\n\nexport type StackBlock =\n | Readonly<{ type: 'frame'; frame: StackFrame }>\n | Readonly<{ type: 'text'; text: string }>\n | Readonly<{ type: 'group'; frames: readonly StackFrame[] }>\n\n/**\n * Fold runs of dependency and runtime frames into groups, so a trace reads as\n * the code the reader owns with the framework's frames one click away.\n *\n * A run of one stays a frame — a disclosure around a single line costs more than\n * it saves. When there is no first-party frame at all nothing is grouped:\n * collapsing everything would hide the entire trace behind a button, which is the\n * opposite of what a reader who owns none of the frames needs.\n */\nexport function groupStackEntries(\n entries: readonly StackEntry[],\n collapse = true\n): readonly StackBlock[] {\n const hasFirstParty = entries.some(\n (entry) => entry.type === 'frame' && entry.frame.kind === 'first-party'\n )\n if (!collapse || !hasFirstParty) return entries\n\n const blocks: StackBlock[] = []\n let run: StackFrame[] = []\n const flush = () => {\n if (run.length >= 2) blocks.push({ type: 'group', frames: run })\n else for (const frame of run) blocks.push({ type: 'frame', frame })\n run = []\n }\n for (const entry of entries) {\n if (entry.type === 'frame' && entry.frame.kind !== 'first-party') {\n run.push(entry.frame)\n continue\n }\n flush()\n blocks.push(entry)\n }\n flush()\n return blocks\n}\n\nconst framesNoun = (count: number, word: string) =>\n `${count.toLocaleString()} ${word} ${count === 1 ? 'frame' : 'frames'}`\n\n/** What a collapsed group says it holds. */\nexport function describeFrameGroup(frames: readonly StackFrame[]): string {\n const count = frames.length\n const dependency = frames.filter((frame) => frame.kind === 'dependency').length\n if (dependency === count) return framesNoun(count, 'dependency')\n if (dependency === 0) return framesNoun(count, 'runtime')\n return `${count.toLocaleString()} dependency and runtime frames`\n}\n\n/** `file:line:col`, with whichever parts the frame has. */\nexport function frameLocation(frame: StackFrame): string | undefined {\n if (frame.file === undefined) return undefined\n const column = frame.column === undefined ? '' : `:${frame.column}`\n const line = frame.line === undefined ? '' : `:${frame.line}`\n return `${frame.file}${line}${line ? column : ''}`\n}\n\nconst LEADING_SPACE = /^[ \\t]*/\n\n/** Remove the indentation every non-blank line shares, so a source snippet sits flush. */\nexport function dedentLines(lines: readonly string[]): string[] {\n let indent = Infinity\n for (const line of lines) {\n if (line.trim() !== '') indent = Math.min(indent, LEADING_SPACE.exec(line)![0].length)\n }\n if (indent === Infinity) return [...lines]\n return lines.map((line) => line.slice(Math.min(indent, LEADING_SPACE.exec(line)![0].length)))\n}\n\nexport type BoundedLines = Readonly<{\n lines: string[]\n /** Lines beyond the bound that are not in `lines` at all. */\n omittedLines: number\n /** Characters beyond the bound, in omitted lines and in the cut end of the last shown line. */\n omittedChars: number\n}>\n\n/**\n * The first lines of `lines`, up to `maxLines` of them and `maxChars` characters\n * between them, with what was left out counted rather than dropped silently. It\n * visits the shown lines and adds up the length of the rest, so the cost does not\n * depend on how much text there is to omit.\n */\nexport function boundLines(\n lines: readonly string[],\n maxLines: number,\n maxChars: number\n): BoundedLines {\n const shown: string[] = []\n let chars = 0\n let index = 0\n let partial = 0\n while (index < lines.length && shown.length < maxLines) {\n const line = lines[index]!\n const room = maxChars - chars\n if (line.length <= room) {\n shown.push(line)\n chars += line.length\n index += 1\n continue\n }\n if (room > 0) {\n shown.push(line.slice(0, room))\n partial = line.length - room\n index += 1\n }\n break\n }\n let omittedChars = partial\n for (let rest = index; rest < lines.length; rest += 1) omittedChars += lines[rest]!.length\n return { lines: shown, omittedLines: lines.length - index, omittedChars }\n}\n"],"mappings":";AAqEA,IAAa,kBAAkB;AAC/B,IAAM,qBAAqB;AAa3B,SAAS,eAAe,OAA4D;CAClF,IAAI,IAAI,MAAM;CACd,OAAO,IAAI,KAAK,MAAM,WAAW,IAAI,CAAC,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC,KAAK,IAAI,KAAK;CACrF,IAAI,MAAM,MAAM,UAAU,MAAM,KAAK,MAAM,IAAI,OAAO,OAAO,MAAM,SAAS,IAAI,GAC9E,OAAO,KAAA;CACT,OAAO;EAAE,OAAO,OAAO,MAAM,MAAM,CAAC,CAAC;EAAG,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC;CAAE;AACtE;;AAGA,SAAgB,cAAc,UAAoE;CAChG,MAAM,OAAO,eAAe,QAAQ;CACpC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,EAAE,MAAM,SAAS;CACvD,MAAM,SAAS,eAAe,KAAK,IA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B,IAAI,KAAK,KAAK,MAAM,IAAI,SAAS,KAAK,IAAI,QAAQ,cAAc,KAAK,IAAI,CAAC,CAAE,EAAE,CAAC,MAAM;CAEvF,IAAI,WAAW,UAAU,OAAO,CAAC,GAAG,KAAK;CACzC,OAAO,MAAM,KAAK,SAAS,KAAK,MAAM,KAAK,IAAI,QAAQ,cAAc,KAAK,IAAI,CAAC,CAAE,EAAE,CAAC,MAAM,CAAC,CAAC;AAC9F;;;;;;;AAgBA,SAAgB,WACd,OACA,UACA,UACc;CACd,MAAM,QAAkB,CAAC;CACzB,IAAI,QAAQ;CACZ,IAAI,QAAQ;CACZ,IAAI,UAAU;CACd,OAAO,QAAQ,MAAM,UAAU,MAAM,SAAS,UAAU;EACtD,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,WAAW;EACxB,IAAI,KAAK,UAAU,MAAM;GACvB,MAAM,KAAK,IAAI;GACf,SAAS,KAAK;GACd,SAAS;GACT;EACF;EACA,IAAI,OAAO,GAAG;GACZ,MAAM,KAAK,KAAK,MAAM,GAAG,IAAI,CAAC;GAC9B,UAAU,KAAK,SAAS;GACxB,SAAS;EACX;EACA;CACF;CACA,IAAI,eAAe;CACnB,KAAK,IAAI,OAAO,OAAO,OAAO,MAAM,QAAQ,QAAQ,GAAG,gBAAgB,MAAM,KAAK,CAAE;CACpF,OAAO;EAAE,OAAO;EAAO,cAAc,MAAM,SAAS;EAAO;CAAa;AAC1E"}
|
|
@@ -100,6 +100,31 @@ export function splitLocation(location: string): { file: string; line?: number;
|
|
|
100
100
|
return { file: last.rest, line: last.value }
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Split the pre-1.78 Rust panic suffix `'message', location`. The message may
|
|
105
|
+
* contain `', ` itself, and the greedy pattern this replaces took the last
|
|
106
|
+
* occurrence with a non-space behind it — this scan keeps that last-wins
|
|
107
|
+
* answer, in one pass, so a message repeating the marker stays linear.
|
|
108
|
+
*/
|
|
109
|
+
function splitRustOldPanic(after: string): { message: string; location: string } | undefined {
|
|
110
|
+
// As in `parsePython`: no `.` in the old pattern could cross a line break.
|
|
111
|
+
if (/[\n\r\u2028\u2029]/.test(after) || !after.startsWith("'")) return undefined
|
|
112
|
+
let close: number | undefined
|
|
113
|
+
let search = 1
|
|
114
|
+
for (;;) {
|
|
115
|
+
const at = after.indexOf("', ", search)
|
|
116
|
+
if (at < 0) break
|
|
117
|
+
search = at + 1
|
|
118
|
+
const start = at + 3
|
|
119
|
+
if (start >= after.length) continue
|
|
120
|
+
// Preserve ECMAScript \S, including NBSP/BOM and Unicode space separators.
|
|
121
|
+
if (/\s/.test(after[start]!)) continue
|
|
122
|
+
close = at
|
|
123
|
+
}
|
|
124
|
+
if (close === undefined) return undefined
|
|
125
|
+
return { message: after.slice(1, close), location: after.slice(close + 3) }
|
|
126
|
+
}
|
|
127
|
+
|
|
103
128
|
const FILE_LIKE = /[\\/]|\.[A-Za-z0-9]{1,6}$/
|
|
104
129
|
const URL_LIKE = /^node:/i
|
|
105
130
|
|
|
@@ -154,13 +179,58 @@ function parseV8(trimmed: string): Draft | undefined {
|
|
|
154
179
|
return draft
|
|
155
180
|
}
|
|
156
181
|
|
|
157
|
-
const
|
|
182
|
+
const PYTHON_PREFIX = 'File "'
|
|
183
|
+
const PYTHON_LINE = '", line '
|
|
184
|
+
const PYTHON_IN = ', in '
|
|
185
|
+
|
|
186
|
+
/** Whether a character is an ASCII digit, as `\d` was in the pattern this replaced. */
|
|
187
|
+
function isDigit(code: number): boolean {
|
|
188
|
+
return code >= 48 && code <= 57
|
|
189
|
+
}
|
|
158
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Read a Python frame: `File "<file>", line <n>[, in <fn>]`.
|
|
193
|
+
*
|
|
194
|
+
* Scanned, not matched. A line repeating the frame shape many times must still
|
|
195
|
+
* cost one pass, so the closing `", line ` is found by walking its candidates
|
|
196
|
+
* left to right. The last valid candidate wins — what the greedy pattern this
|
|
197
|
+
* replaces would have settled on — so a file path containing a quote still
|
|
198
|
+
* parses exactly as it always did.
|
|
199
|
+
*/
|
|
159
200
|
function parsePython(trimmed: string): Draft | undefined {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
201
|
+
// `.` never matches a line break, so the whole-line pattern this replaces
|
|
202
|
+
// could not have matched a string containing one either.
|
|
203
|
+
if (/[\n\r\u2028\u2029]/.test(trimmed) || !trimmed.startsWith(PYTHON_PREFIX)) return undefined
|
|
204
|
+
let close: number | undefined
|
|
205
|
+
let digits = 0
|
|
206
|
+
let rest = 0
|
|
207
|
+
let hasIn = false
|
|
208
|
+
let search = PYTHON_PREFIX.length
|
|
209
|
+
for (;;) {
|
|
210
|
+
const at = trimmed.indexOf(PYTHON_LINE, search)
|
|
211
|
+
if (at < 0) break
|
|
212
|
+
search = at + 1
|
|
213
|
+
let end = at + PYTHON_LINE.length
|
|
214
|
+
const start = end
|
|
215
|
+
while (end < trimmed.length && isDigit(trimmed.charCodeAt(end))) end += 1
|
|
216
|
+
if (end === start) continue
|
|
217
|
+
if (end < trimmed.length && !trimmed.startsWith(PYTHON_IN, end)) continue
|
|
218
|
+
close = at
|
|
219
|
+
digits = end - start
|
|
220
|
+
rest = end
|
|
221
|
+
hasIn = end < trimmed.length
|
|
222
|
+
}
|
|
223
|
+
if (close === undefined) return undefined
|
|
224
|
+
const draft: Draft = {
|
|
225
|
+
raw: trimmed,
|
|
226
|
+
format: 'python',
|
|
227
|
+
file: trimmed.slice(PYTHON_PREFIX.length, close),
|
|
228
|
+
line: Number(trimmed.slice(rest - digits, rest)),
|
|
229
|
+
}
|
|
230
|
+
if (hasIn) {
|
|
231
|
+
const fn = trimmed.slice(rest + PYTHON_IN.length)
|
|
232
|
+
if (fn) draft.function = fn
|
|
233
|
+
}
|
|
164
234
|
return draft
|
|
165
235
|
}
|
|
166
236
|
|
|
@@ -341,13 +411,13 @@ function liftHeader(entries: StackEntry[], format: StackTraceFormat): StackTrace
|
|
|
341
411
|
if (at < 0) return undefined
|
|
342
412
|
const type = first.slice(0, at).trim()
|
|
343
413
|
const after = first.slice(at + 4)
|
|
344
|
-
const old =
|
|
414
|
+
const old = splitRustOldPanic(after)
|
|
345
415
|
let consumed = 1
|
|
346
416
|
let message: string
|
|
347
417
|
let location: string | undefined
|
|
348
418
|
if (old) {
|
|
349
|
-
message = old
|
|
350
|
-
location = old
|
|
419
|
+
message = old.message
|
|
420
|
+
location = old.location
|
|
351
421
|
} else {
|
|
352
422
|
location = after.replace(/:$/, '')
|
|
353
423
|
const body: string[] = []
|
package/package.json
CHANGED
|
@@ -100,6 +100,31 @@ export function splitLocation(location: string): { file: string; line?: number;
|
|
|
100
100
|
return { file: last.rest, line: last.value }
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Split the pre-1.78 Rust panic suffix `'message', location`. The message may
|
|
105
|
+
* contain `', ` itself, and the greedy pattern this replaces took the last
|
|
106
|
+
* occurrence with a non-space behind it — this scan keeps that last-wins
|
|
107
|
+
* answer, in one pass, so a message repeating the marker stays linear.
|
|
108
|
+
*/
|
|
109
|
+
function splitRustOldPanic(after: string): { message: string; location: string } | undefined {
|
|
110
|
+
// As in `parsePython`: no `.` in the old pattern could cross a line break.
|
|
111
|
+
if (/[\n\r\u2028\u2029]/.test(after) || !after.startsWith("'")) return undefined
|
|
112
|
+
let close: number | undefined
|
|
113
|
+
let search = 1
|
|
114
|
+
for (;;) {
|
|
115
|
+
const at = after.indexOf("', ", search)
|
|
116
|
+
if (at < 0) break
|
|
117
|
+
search = at + 1
|
|
118
|
+
const start = at + 3
|
|
119
|
+
if (start >= after.length) continue
|
|
120
|
+
// Preserve ECMAScript \S, including NBSP/BOM and Unicode space separators.
|
|
121
|
+
if (/\s/.test(after[start]!)) continue
|
|
122
|
+
close = at
|
|
123
|
+
}
|
|
124
|
+
if (close === undefined) return undefined
|
|
125
|
+
return { message: after.slice(1, close), location: after.slice(close + 3) }
|
|
126
|
+
}
|
|
127
|
+
|
|
103
128
|
const FILE_LIKE = /[\\/]|\.[A-Za-z0-9]{1,6}$/
|
|
104
129
|
const URL_LIKE = /^node:/i
|
|
105
130
|
|
|
@@ -154,13 +179,58 @@ function parseV8(trimmed: string): Draft | undefined {
|
|
|
154
179
|
return draft
|
|
155
180
|
}
|
|
156
181
|
|
|
157
|
-
const
|
|
182
|
+
const PYTHON_PREFIX = 'File "'
|
|
183
|
+
const PYTHON_LINE = '", line '
|
|
184
|
+
const PYTHON_IN = ', in '
|
|
185
|
+
|
|
186
|
+
/** Whether a character is an ASCII digit, as `\d` was in the pattern this replaced. */
|
|
187
|
+
function isDigit(code: number): boolean {
|
|
188
|
+
return code >= 48 && code <= 57
|
|
189
|
+
}
|
|
158
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Read a Python frame: `File "<file>", line <n>[, in <fn>]`.
|
|
193
|
+
*
|
|
194
|
+
* Scanned, not matched. A line repeating the frame shape many times must still
|
|
195
|
+
* cost one pass, so the closing `", line ` is found by walking its candidates
|
|
196
|
+
* left to right. The last valid candidate wins — what the greedy pattern this
|
|
197
|
+
* replaces would have settled on — so a file path containing a quote still
|
|
198
|
+
* parses exactly as it always did.
|
|
199
|
+
*/
|
|
159
200
|
function parsePython(trimmed: string): Draft | undefined {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
201
|
+
// `.` never matches a line break, so the whole-line pattern this replaces
|
|
202
|
+
// could not have matched a string containing one either.
|
|
203
|
+
if (/[\n\r\u2028\u2029]/.test(trimmed) || !trimmed.startsWith(PYTHON_PREFIX)) return undefined
|
|
204
|
+
let close: number | undefined
|
|
205
|
+
let digits = 0
|
|
206
|
+
let rest = 0
|
|
207
|
+
let hasIn = false
|
|
208
|
+
let search = PYTHON_PREFIX.length
|
|
209
|
+
for (;;) {
|
|
210
|
+
const at = trimmed.indexOf(PYTHON_LINE, search)
|
|
211
|
+
if (at < 0) break
|
|
212
|
+
search = at + 1
|
|
213
|
+
let end = at + PYTHON_LINE.length
|
|
214
|
+
const start = end
|
|
215
|
+
while (end < trimmed.length && isDigit(trimmed.charCodeAt(end))) end += 1
|
|
216
|
+
if (end === start) continue
|
|
217
|
+
if (end < trimmed.length && !trimmed.startsWith(PYTHON_IN, end)) continue
|
|
218
|
+
close = at
|
|
219
|
+
digits = end - start
|
|
220
|
+
rest = end
|
|
221
|
+
hasIn = end < trimmed.length
|
|
222
|
+
}
|
|
223
|
+
if (close === undefined) return undefined
|
|
224
|
+
const draft: Draft = {
|
|
225
|
+
raw: trimmed,
|
|
226
|
+
format: 'python',
|
|
227
|
+
file: trimmed.slice(PYTHON_PREFIX.length, close),
|
|
228
|
+
line: Number(trimmed.slice(rest - digits, rest)),
|
|
229
|
+
}
|
|
230
|
+
if (hasIn) {
|
|
231
|
+
const fn = trimmed.slice(rest + PYTHON_IN.length)
|
|
232
|
+
if (fn) draft.function = fn
|
|
233
|
+
}
|
|
164
234
|
return draft
|
|
165
235
|
}
|
|
166
236
|
|
|
@@ -341,13 +411,13 @@ function liftHeader(entries: StackEntry[], format: StackTraceFormat): StackTrace
|
|
|
341
411
|
if (at < 0) return undefined
|
|
342
412
|
const type = first.slice(0, at).trim()
|
|
343
413
|
const after = first.slice(at + 4)
|
|
344
|
-
const old =
|
|
414
|
+
const old = splitRustOldPanic(after)
|
|
345
415
|
let consumed = 1
|
|
346
416
|
let message: string
|
|
347
417
|
let location: string | undefined
|
|
348
418
|
if (old) {
|
|
349
|
-
message = old
|
|
350
|
-
location = old
|
|
419
|
+
message = old.message
|
|
420
|
+
location = old.location
|
|
351
421
|
} else {
|
|
352
422
|
location = after.replace(/:$/, '')
|
|
353
423
|
const body: string[] = []
|