errorview

package
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package errorview renders a structured wrapped-error chain as a collapsing tree: per-stream sub-headers, per-fact rows showing message (red), stack frame triple (monospace muted), and CBOR diagnostic of any attached structured data (in a dark canvas Frame). Lifted out of the logviewer detail pane so any consumer of an `eh.MarshalError`-shaped chain — observability dashboards, crash reports, debug overlays — can render it with the same look without re-implementing the per-fact dispatch and wrap discipline.

Usage:

r := errorview.New(ids, "card-err").DefaultOpen(false)
r.Render(ctx)

Renderer is a value type; fluent setters return modified copies so a base config is safe to share. All widget IDs are derived from the caller-supplied WidgetIdStack under the per-Renderer idPrefix, so two renderers on the same stack can't collide as long as their prefixes differ.

Wire-shape adapters live with each consumer (e.g. logviewer.toErrorviewContext bridges factsstore.LogErrorContext → errorview.Context); errorview itself stays decoupled from any particular decoder so it composes with other transports.

Index

Constants

This section is empty.

Variables

View Source
var PackageProps = packageprops.Props{
	WASMWASI:         packageprops.WASMCompiles,
	WASMJS:           packageprops.WASMCompiles,
	WASMFreestanding: packageprops.WASMCompiles,
}

PackageProps records this package's curated properties (ADR-0080). Seeded by `wasmsurvey props generate`; curate by hand, then `wasmsurvey props verify`.

Functions

func FormatFrame

func FormatFrame(f Fact) (s string)

FormatFrame composes the Fact's frame triple into a "func @ source:line" string. Exported so callers that want to render frames their own way (without going through the Renderer) reuse the same composition rules. eh's CompactStackTrace already trimmed the longest common path prefix on the producer side, so Source paths arrive at a tractable length.

Types

type Context

type Context struct {
	Streams []Stream
}

Context is the typed root of an error chain decode. Empty (zero Streams) is a valid no-op input — the Renderer short-circuits instead of producing an "error chain — 0 streams" header.

func (Context) IsEmpty

func (inst Context) IsEmpty() (ok bool)

IsEmpty reports whether the context carries no facts. Used by callers who want to gate UI affordances (e.g. an "Inspect error chain" button) on the presence of structured error info.

type Fact

type Fact struct {
	Msg      string
	Source   string
	Line     string
	Function string
	Data     []byte
	DataDiag string
	Id       uint64
	ParentId uint64
}

Fact is one node of an error chain. Mirrors the wire shape that boxer's eh.MarshalError emits per fact:

  • Msg: the error's .Error() text (omitted on per-frame stub facts that only carry a stack frame).
  • Source / Line / Function: the stack frame triple — present for stack-bearing facts, empty for message-only facts.
  • Data / DataDiag: structured-data attached via eb.Build — Data is the raw CBOR, DataDiag the cbor.Diagnose output.
  • Id / ParentId: linkage forming the error tree; renderers today display facts in chain order (linear) but the fields are preserved for callers that want to walk the tree shape.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer is the configured error-chain viewer. Holds a pointer to the caller's WidgetIdStack so widget IDs derive deterministically from the caller's id scope plus the per-Renderer idPrefix — two renderers on the same stack don't collide as long as their prefixes differ.

Renderer is intentionally a value (not a pointer): config changes don't mutate the caller's instance, which makes a "build a base config once, override per-call" pattern safe.

func New

func New(ids *c.WidgetIdStack, idPrefix string) (inst Renderer)

New builds a Renderer with sensible defaults: DefaultOpen on so freshly-rendered chains reveal their facts immediately, Indent 12 px matching the fieldview default. The idPrefix scopes every widget ID this Renderer emits so multiple renderers can share an ids stack without collisions; pass a stable short string ("card-err" / "log-err" / "trace").

func (Renderer) DefaultOpen

func (inst Renderer) DefaultOpen(v bool) (out Renderer)

DefaultOpen sets the initial collapsed/expanded state of the per-stream CollapsingHeaders. The outer "error chain — N streams" header tracks the same default. Set false for deep chains where the initial summary should be terse.

func (Renderer) ErrorFg

func (inst Renderer) ErrorFg(col color.Color) (out Renderer)

ErrorFg overrides the foreground colour used for fact messages. Default is a soft red (Tailwind red-300) calibrated to read on the standard dark egui theme. Override when adopting a different theme palette.

func (Renderer) Indent

func (inst Renderer) Indent(v float32) (out Renderer)

Indent sets the per-fact left padding before frame triples and structured-data blocks, in pixels. Default 12. Zero is allowed for a flat layout.

func (Renderer) MutedFg

func (inst Renderer) MutedFg(col color.Color) (out Renderer)

MutedFg overrides the foreground colour used for stack-frame triples. Default is Tailwind gray-400.

func (Renderer) Render

func (inst Renderer) Render(ctx Context)

Render draws the error chain at the current ui scope. Outer CollapsingHeader titled "error chain — N stream(s)"; per stream a sub-header titled "<name> · M fact(s)"; per fact a message line, an optional indented frame-triple line, and an optional dark-canvas Frame with the CBOR diagnostic of structured data.

No outer wrapper is added beyond the top-level CollapsingHeader; the caller owns whatever surrounding scope (panel, Frame, dialog) frames the viewer.

Empty contexts (no streams or no facts) short-circuit so the UI doesn't grow an "error chain — 0 streams" header.

type Stream

type Stream struct {
	Name  string
	Facts []Fact
}

Stream is one bucket of facts grouped by stack identity. Name is "no-stack" (errors without stack info) or "stack-N" (the Nth deduplicated stack trace shared by one or more wrap levels). Facts are in chain order — the outermost wrap message first, then any per-frame stubs interleaved per the producer's materialize pass.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL