guard

package
v0.8.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 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

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