Documentation
¶
Overview ¶
utils/panic_log.go — pig panic containment (pig-internal; no pi counterpart). pi is single-threaded JS: an uncaught throw crashes the Bun process and the terminal scrolls the stack away. pig is goroutine-based, so panics are contained at hot-path spawn sites (recover + log + keep running) and every containment writes a persistent report here.
Log location: `$PIG_CODING_AGENT_DIR/logs/` or `~/.pig/agent/logs/` (mirrors codingagent/config.go's directory resolution; tui is a leaf package with the same sync duty — see tui/tui.go). The 20 newest reports are kept, older ones are pruned on each write.
Limits (documented, by design):
- Fatal runtime errors (concurrent map writes, OOM, stack overflow) are not recoverable in Go and still kill the process — nothing can log them from inside the dying runtime.
- A contained panic may leave the failing unit half-updated (e.g. a partially built frame); the report is the source of truth for diagnosis. See docs/feat/PANIC-RESILIENCE.md.
Package utils provides shared leaf-level helpers used across pig packages (pig-internal; no corresponding pi package, see AGENTS.md §3.1 exceptions like constants/).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Guard ¶
Guard runs fn synchronously and contains a panic, returning the report path and whether fn panicked. Used at dispatch sites that need to react (show a UI notice, count the failure) rather than silently continue.
func LogPanic ¶
LogPanic writes a panic report for the given component and returns the report path (empty when the write failed — logging is best-effort and must never panic or block the recovering goroutine). The report contains the panic value, the panicking goroutine's stack, and a full goroutine dump (deadlock context after containment).
func PanicLogDirectory ¶
func PanicLogDirectory() string
PanicLogDirectory returns the directory panic reports are written to: `$PIG_CODING_AGENT_DIR/logs` falling back to `~/.pig/agent/logs` (and finally the OS temp directory when the home directory is unavailable). The env name and fallback mirror codingagent/config.go's ConfigDirName resolution; this leaf package cannot import codingagent, so the two must be kept in sync (same duty as tui/tui.go's copy).
func RecoverPanic ¶
func RecoverPanic(component string)
RecoverPanic recovers the current goroutine's panic, logs it, and lets execution continue — the defer-site containment helper:
defer utils.RecoverPanic("component.name")
func SameFuncValue ¶
SameFuncValue reports whether two func values refer to the same function. Go func values are not comparable; code-pointer equality stands in for the JS reference identity the pi ports rely on (e.g. removing a registered listener, `this.agent.streamFunction === streamSimple`). It is exact for the register-then-unregister-same-reference pattern, but cannot distinguish two distinct closure instances from the same literal — comparison then depends on compiler inlining, so freshly-built closures must not be matched with it. A nil or non-func value yields false.
Types ¶
This section is empty.