In Development Package, API may change between versions.

import "github.com/egdaemon/eg/runtime/x/wasi/egerrors"

Package egerrors provides combinators for handling errors returned by operations.

func Chain

func Chain(op eg.Runnable, fallbacks ...eg.Runnable) eg.OpFn

Chain runs the operation, if it fails each fallback is attempted in order until one succeeds. if all of them fail then the errors are joined and returned.

func Compact

func Compact(errs ...error) error

Compact returns the first error in the set, if any.

func Ignore

func Ignore(op eg.Runnable, errs ...error) eg.OpFn

Ignore errors returned by the operation that match any of the provided errors (errors.Is). if no errors are provided then all errors are ignored.

func When

func When(op eg.Runnable, do eg.Runnable, errs ...error) eg.OpFn

When the operation fails with an error matching any of the provided errors (errors.Is) run the 'do' operation, the result of 'do' replaces the original error. if no errors are provided then any error triggers 'do'. errors that don't match are returned as is.

func Zero

func Zero[T any](v T, err error) T
⬤