safe

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package safe turns panics into ordinary errors so a bug in one unit of work (a page, a plugin hook, an embedded-JS evaluation) is reported as a normal diagnostic instead of crashing the whole compiler. Set KRATE_DEBUG=1 to let panics propagate with their original stack for debugging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Guard

func Guard(fn func(), onPanic func(error))

Guard runs fn and recovers any panic, reporting it to onPanic (which may be nil). Intended for fire-and-forget goroutines whose return value is discarded.

func Recover

func Recover(v any) error

Recover converts a recover() value into an error. It always prints the value and stack to stderr so a contained panic is never silent, regardless of KRATE_DEBUG. When KRATE_DEBUG is set the panic is re-thrown unchanged.

func Run

func Run(fn func() error) (err error)

Run executes fn, converting a panic into an error returned to the caller.

Types

type PanicError

type PanicError struct {
	Value any
	Stack []byte
}

PanicError wraps a recovered panic value together with the stack at the point it was recovered.

func (*PanicError) Error

func (e *PanicError) Error() string

Jump to

Keyboard shortcuts

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