guard

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package guard is the one place a panic stops being fatal. codeaf is event-sourced: the graph loses nothing when a goroutine dies, so a fault should be absorbed, recorded, and degraded around — never allowed to take the terminal surface down while the user is working.

It is deliberately three functions and one error type. Anything larger would be a framework, and a framework is not what a deferred recover needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go(scope string, fn func())

Go spawns fn under Recover. Every fire-and-forget goroutine in codeaf starts here, so "no goroutine can kill the surface" is one grep, not a habit.

func IsFault

func IsFault(err error) bool

IsFault reports whether err came from a recovered panic, which is how a caller tells "the work failed" from "the work faulted".

func Note

func Note(scope string, recovered any) error

Note records a recovered panic and returns the error that stands in for it. Call it from a deferred recover when the fault must become a result rather than end the goroutine. The stack is written once, here.

func Recover

func Recover(scope string)

Recover absorbs a panic in the deferring goroutine and lets it end quietly: `defer guard.Recover("narrator")`. Use it where there is no result to carry the fault — a fire-and-forget spawn whose only obligation is not to crash.

func SetOnFault

func SetOnFault(fn func(scope string, stack []byte))

SetOnFault installs the hook, or removes it with nil.

Types

type Fault

type Fault struct {
	Scope     string
	Recovered any
	Stack     []byte
}

Fault is what a recovered panic becomes: an ordinary error the caller can record, fail a node with, or hand back to a model as text.

func (*Fault) Error

func (f *Fault) Error() string

Error reads as one sentence because it ends up in node failure text and in tool results the model has to act on.

Jump to

Keyboard shortcuts

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