Documentation
¶
Overview ¶
Package on_error provides the `@on_error { when ... -> target; else -> target }` block. On a runtime error, WrapPipeline wraps the compiled program with a CatchAny handler that evaluates each rule's condition against the error and routes to the matching target.
Typical use:
@on_error {
when error.kind == "Timeout" -> cov.recoverable
when error.kind == "NotFound" -> log.info
else -> error.info
}
Index ¶
Constants ¶
const ID = "on_error"
Variables ¶
var Directive = core.Directive{
Name: "on_error",
Example: `@on_error {
when error.kind == "Timeout" -> cov.recoverable
else -> runtime.noop
}`,
Handler: handleDirective,
}
Directive parses the `@on_error { ... }` block and writes it to meta["on_error"].
var ErrorInfoAction = action.New("error.info", func(ctx context.Context, _ any) (map[string]any, error) { recovered, ok := contracts.RecoveredErrorFrom(ctx) if !ok || recovered == nil { return nil, xerr.NotFound("no recovered error in context") } return map[string]any{ "kind": recovered.Kind, "message": recovered.Err.Error(), }, nil }). Description("Return information about the recovered error"). Tag("error", "recovery"). Build()
ErrorInfoAction reads the recovered error from the context and returns it as a map. It is the default target for rules that want to inspect the original error without further processing.
Functions ¶
Types ¶
type ErrorGuardCase ¶ added in v0.16.0
ErrorGuardCase handles one built-in Kernel kind or the optional else arm.
type ErrorGuardExpr ¶ added in v0.16.0
type ErrorGuardExpr struct {
Protected core.Expr
Cases []ErrorGuardCase
}
ErrorGuardExpr wraps any preceding expression and conditionally recovers its runtime error using ordered Kernel-kind cases.
func (*ErrorGuardExpr) Analyze ¶ added in v0.16.0
func (g *ErrorGuardExpr) Analyze(resolver core.CapabilityResolver) error
func (*ErrorGuardExpr) Build ¶ added in v0.16.0
func (g *ErrorGuardExpr) Build(ctx context.Context, buildCtx *core.BuildContext) (action.AnyAction, error)
func (*ErrorGuardExpr) Children ¶ added in v0.16.0
func (g *ErrorGuardExpr) Children() []core.Expr
func (*ErrorGuardExpr) Node ¶ added in v0.16.0
func (*ErrorGuardExpr) Node()