Stack Trace
An error read from its printed trace: the type and message, opening to its frames, with library frames folded away, file paths that open, and the whole trace to copy.
- ProjectList
- ProjectsPage
Installation
npx shadcn@latest add "@aiellie/stack-trace"shadcn needs the @aiellie registry in components.json first. npx aiellie add stack-trace adds it on its first run, then installs the same way.
Stack Trace reads an error from the text it was printed as and shows its type and message, opening to its frames. Frames in node_modules and Node's own internals fold away behind one row, so the frames in your code come first. A file path can open the file, and the whole trace can be copied.
It reads V8's frames (Chrome, Node) and Firefox's and Safari's, and leaves out any line it can't read.
Getting started
Pass the trace
Give it
error.stack, or a trace from a log or a tool's output.components/run-error.tsximport { StackTrace, StackTraceCopy, StackTraceFrames, StackTraceHeader, } from "@/components/aiellie/stack-trace" export function RunError({ trace }: { trace: string }) { return ( <StackTrace trace={trace} onOpenFile={(frame) => openInEditor(frame.file, frame.line)} > <StackTraceHeader> <StackTraceCopy /> </StackTraceHeader> <StackTraceFrames /> </StackTrace> ) }
Anatomy
<div data-slot="stack-trace"> {/* Base UI Collapsible */}
<div data-slot="stack-trace-header">
<button /> {/* the type, the message and the frame count */}
<button data-slot="stack-trace-copy" />
</div>
<div data-slot="stack-trace-frames">
<ol>
<li data-library />
</ol>
</div>
</div>The header's children sit at its end, outside the button that opens it. Frames read left to right whatever the page's direction, since they're code. parseStackTrace is exported too, for reading a trace without showing it.
Examples
Show library frames
showLibrary shows every frame from the start.
- flattenlib/tree.ts:8:12
- Array.map<anonymous>
- flattenlib/tree.ts:9:30
- Module._compilenode:internal/modules/cjs/loader:1256:14
API reference
StackTrace
| Prop | Type | Default | Description |
|---|---|---|---|
trace | string | required | The error's text as it was printed. |
onOpenFile | (frame: StackFrame) => void | Makes each of your frames' paths a button. |
All other Collapsible.Root props are forwarded.
StackTraceFrames
| Prop | Type | Default | Description |
|---|---|---|---|
showLibrary | boolean | false | Shows library frames from the start. |
StackFrame
| Field | Type | Default | Description |
|---|---|---|---|
file | string | required | |
name | string | The function, when the trace names one. | |
line, column | number | ||
library | boolean | required | In node_modules or Node's internals. |
raw | string | required | The line it was read from. |
StackTraceCopy takes a tooltip, "Copy trace" by default.