utils

package
v0.86.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Guard(component string, fn func()) (logPath string, panicked bool)

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

func LogPanic(component string, r any) string

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

func SameFuncValue[T any](a, b T) bool

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.

Jump to

Keyboard shortcuts

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