Stack Trace
FreeA readable error. Pass an `Error` or the text of a stack trace and it shows the name and message, then function, file, line and column for each frame — parsed from V8 (Chrome, Edge, Node), SpiderMonkey (Firefox), JavaScriptCore (Safari) and generic `file:line:col` traces. Runs of library frames (`node_modules`, Node internals, bundler runtimes, native code) fold behind one "Show N library frames" toggle each, so your own frames are on screen; frames can emit `frameClick`; copy takes the original text. `svParseStackTrace()` is exported.
Complexity tier: Primitive Presents a value: held to semantic markup and contrast, laid out with logical properties so it mirrors under right-to-left, and with what it does on paper decided.
import { SvStackTraceComponent } from '@styloviz/code-block';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Open a frame in the editor
<sv-stack-trace [trace]="event.stack" [frameClickable]="true" (frameClick)="open($event)" /> open(frame: SvStackFrame) { window.open(`vscode://file/${root}/${frame.file}:${frame.line}:${frame.column}`); }
Decide what counts as library code
<sv-stack-trace [trace]="trace" [isLibraryFrame]="isVendor" /> isVendor = (f: SvStackFrame) => svIsLibraryFrame(f) || (f.file ?? '').includes('/vendor/');
The parser on its own
import { svParseStackTrace } from '@styloviz/code-block'; const { name, message, frames } = svParseStackTrace(error.stack ?? ''); // frames[0]: { functionName: 'total', file: 'src/cart.ts', line: 42, column: 17, format: 'v8', … }
When to use
The detail view of an error in a monitoring, logging or support tool. A developer-facing error page or an admin "job failed" panel. Use a plain alert for a user-facing error message — a stack trace is for developers.
Async states
None — this component has nothing to load, so it has no loading, empty or error state to drive.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| trace | string | Error | null | null | The trace: an `Error` (its `stack`, `name` and `message` are read) or the text of a stack trace, as logged. |
| collapseLibraryFrames | boolean | true | Fold each run of library frames behind a "Show N library frames" toggle. |
| isLibraryFrame | (frame: SvStackFrame) => boolean | svIsLibraryFrame | Decides which frames are library code. The default, `svIsLibraryFrame`, matches `node_modules`, `node:` and `internal/` paths, webpack and Vite runtimes, zone.js, polyfills and native frames. |
| frameClickable | boolean | false | Render each frame that has a file as a button that emits `frameClick`. |
| copyable | boolean | true | Show a button that copies the trace as text. |
| maxHeight | string | '' | Max height of the frame list, e.g. `'24rem'`; it scrolls past that. `''` for none. |
| ariaLabel | string | 'Stack trace' | Accessible name of the region. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| frameClick | SvStackFrame | A frame was activated (only while `frameClickable`). Payload: the parsed frame. |
| copied | string | Emits the copied text after a successful clipboard write. |
Customization & theming
The header paints from the `danger` token; application frames' locations from `primary`; library frames are muted `gray`. `isLibraryFrame` replaces the default predicate; `frameClickable`, `copyable` and `maxHeight` tune the rest. `svParseStackTrace`, `svParseStackFrame`, `svIsLibraryFrame` and `svStackFrameLocation` are exported. All visible strings are `codeBlock` labels in 12 language packs.
Best practices
Do: Pass the `Error` itself when you have it: Firefox and Safari leave the name and message out of `stack`, and the component fills them in from the object. Do: Keep `collapseLibraryFrames` on — the frames in your own code are the ones a reader acts on. Don't: Do not show it to end users of a public product; traces leak paths and structure. Tip: Resolve frames through your source maps before passing the text, and the rows show original files and lines.
Accessibility
The trace is a named region; frames are an ordered list named with its frame count. Each library run's toggle is a button with `aria-expanded` and `aria-controls`, and says how many frames it shows or hides. Clickable frames are real buttons named by their function and location; frames without a file stay text. Copy confirms through a status message, and says so when the clipboard is unavailable. Messages and paths render as text — a message containing markup shows the characters.
Feedback on Stack Trace
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.