This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Panic
import std/panicpanic.kz · 2 tors · ~[comptime]
// std/panic — program-wide answers to panic branches
// `?!` is the optional-to-handle branch kind: a caller that writes `| bad v |>`
// answers it; a caller that doesn't gets a synthesized @panic at the site, and
// --panic-branches=strict can enumerate every such site at compile time. Lazy
// programs leave those holes; careful programs write forty identical arms.
// std/panic is the third option: a spelled, pattern-scoped graft that supplies
// the arm nobody wrote — the hole answered once instead of forty times, and
// what it does not cover still crashes.
//
// std/panic:catch(net:* -> oom)
// ! oom f when f.retryable |> backoff(f)
// ! oom f |> std/panic:die("unrecoverable")
//
// The parens expression is tap's selector grammar verbatim: `source` is a
// tor-path glob (`risky`, `net:*`, `std.io:print.*`) selecting call sites;
// `-> dest` is an optional panic-branch-name glob selecting which `?!`
// outcomes. The `!` arms are effect branches — deliberately non-exhaustive:
// each names a panic branch it answers, with `when` filters allowed. At every
// matched site where that `?!` is unhandled, the arm body is grafted in as the
// missing `|` arm (is_transformed_subtree — proven by std/control:capture).
// If every grafted arm for a branch is guarded, a synthesized unguarded tail
// arm re-panics at runtime: silence still means crash.
//
// Verdict discipline: a `?!` is the callee's terminal product — nothing
// resumes it. The grafted arm IS the tail of the abandoned path, and its end
// is the answer to "was the panic resolved": `=> name payload` forwards the
// same outcome upward (not resolved — the frame above decides), `=> other`
// resolves as a different declared outcome, `die` kills here, and a bare end
// abandons the path. Abandonment is legal only where the path is allowed to
// end: inside a producing flow (an impl that owes its caller an outcome), an
// arm with a bare end would trade a loud crash for a dead path — so catch
// refuses to graft it there unless every leaf ends in a verdict.
//
// What a catch can never do is quiet a crash it did not name.
//
// DIE - owned panic, one verb per target
// The synthesized hole's bodies are already per-target panic emission; die
// makes that verb user-callable from inside a grafted arm (or anywhere).
~[runtime] pub tor die { msg: string } -> noreturn// CATCH - the site-pattern graft
~[comptime|transform] pub tor catch {
expr: Expression,
reporter: std/compiler:*ErrorReporter
}