on_error

package
v0.18.0 Latest Latest
Warning

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

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

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

View Source
const ID = "on_error"

Variables

View Source
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"].

View Source
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

func Bundle

func Bundle(_ map[string]string) core.Bundle

func Library

func Library() action.Library

Library returns the extension's directives and the error.info action as a kernel library.

Types

type Config

type Config struct {
	Rules      []Rule
	ElseTarget string
}

Config is the parsed @on_error block.

type ErrorGuardCase added in v0.16.0

type ErrorGuardCase struct {
	Kind   xerr.Kind
	IsElse bool
	Body   core.Expr
}

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()

type Rule

type Rule struct {
	Condition string
	Target    string
}

Rule is a single conditional mapping in a @on_error block.

Jump to

Keyboard shortcuts

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