ers

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 25

Documentation

Overview

Package ers provides some very basic error aggregating and handling tools, as a companion to erc.

The packages are similar, though ers is smaller and has no dependencies outside of a few packages in the standard library, whereas erc is more tightly integrated into fun's ecosystem and programming model.

ers has an API that is equivalent to the standard library errors package, with some additional tools and minor semantic differences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As is a wrapper around errors.As to allow ers to be a drop in replacement for errors.

func Cast

func Cast(e any) error

Cast returns e if e is an error and otherwise returns nil.

func GetTime

func GetTime(err error) time.Time

GetTime unwraps the error looking for an error type that implements the timestamp interface:

interface{ Time() time.Time }

and, if so returns the output of that method. Otherwise, GetTime returns a zeroed time object. Any Error implementation can implement this interface, though the Timestamp type provides a basic implementation.

func If added in v0.13.0

func If(cond bool, err error) error

If constructs an ers.Error-typed error value IF the conditional is true, and returns nil otherwise.

func Is

func Is(err error, targets ...error) bool

Is returns true if the error is one of the target errors, (or one of it's constituent (wrapped) errors is a target error. ers.Is uses errors.Is.

func IsError

func IsError(err error) bool

IsError returns true when the error is non-nill. Provides the inverse of IsOk().

func IsExpiredContext added in v0.10.5

func IsExpiredContext(err error) bool

IsExpiredContext checks an error to see if it, or any of it's parent contexts signal that a context has expired. This covers both canceled contexts and ones which have exceeded their deadlines.

func IsInvariantViolation

func IsInvariantViolation(r any) bool

IsInvariantViolation returns true if the argument is or resolves to ers.ErrInvariantViolation.

func IsOk added in v0.12.0

func IsOk(err error) bool

IsOk returns true when the error is nil, and false otherwise, and mostly exists for clarity at call sites in bool/IsOk check relevant contexts.

func IsTerminating

func IsTerminating(err error) bool

IsTerminating returns true if the error is one of the sentinel errors used by fun (and other packages!) to indicate that processing/iteration has terminated. (e.g. context expiration, or io.EOF.)

func New

func New(str string) error

New constructs an error object that uses the Error as the underlying type.

func NewWithTime

func NewWithTime(e string) error

NewWithTime creates a new error object with the provided string.

func Unwind

func Unwind(in error) []error

Unwind assembles the full "unwrapped" list of all component errors. Supports error implementations where the Unwrap() method returns either error or []error.

Unwind provides a special case of the dt.Unwind operation.

If an error type implements interface{ Unwind() []error }, this takes precedence over Unwrap when unwinding errors, to better support the Stack type and others where the original error is nested within the unwrapped error objects.

func Unwrap

func Unwrap(err error) error

Unwrap is a wrapper around errors.Unwrap to allow ers to be a drop in replacement for errors.

func When added in v0.10.4

func When(cond bool, val string) error

When constructs an error from the provided string when the condition is true, and returns nil otherwise.

func Whenf added in v0.10.4

func Whenf(cond bool, tmpl string, args ...any) error

Whenf constructs an error (using fmt.Errorf) IF the conditional is true, and returns nil otherwise.

func WithTime

func WithTime(err error) error

WithTime wraps an error with a timestamp implementation. The output of time.Now will be captured when WithTime returns, and can be accessed via the GetTime method or using the '%+v' formatting argument.

The Timestamp errors, correctly supports errors.Is and errors.As, passing through to the wrapped error.

func Wrap

func Wrap(err error, annotation string) error

Wrap returns an annotated error if the input error is non-nil, and returns nil otherwise.

This, roughly mirrors the api "github/pkg/errors.Wrap" but takes advantage of newer standard library error wrapping tools.

func Wrapf

func Wrapf(err error, tmpl string, args ...any) error

Wrapf returns an annotated error using the given sprintf-style template and arguments, and returns nil otherwise.

This, roughly mirrors the api "github/pkg/errors.Wrapf" but takes advantage of newer standard library error wrapping tools.

Types

type Error

type Error string

Error is a type alias for building/declaring sentinel errors as constants.

In addition to nil error interface values, the Empty string is, considered equal to nil errors for the purposes of Is(). errors.As correctly handles unwrapping and casting Error-typed error objects.

const ErrContainerClosed Error = Error("container is closed")

ErrContainerClosed is returned for operations against a container that has been closed or finished.

const ErrCurrentOpAbort Error = Error("abort current operation")

ErrCurrentOpAbort is used to signal that a retry function or other looping operation that the loop should exit. ErrCurrentOpAbort should be handled like "break", and should not be returned to callers or aggregated with other errors.

const ErrCurrentOpSkip Error = Error("skip current operation")

ErrCurrentOpSkip is used to signal that a retry function or other looping loop should continue. In most cases, this error should not be returned to callers or aggregated with other errors.

const ErrImmutabilityViolation Error = Error("immutability violation")

ErrImmutabilityViolation is an returned by some operations or invariant violations when an operation attempts to modify logically immutable value.

const ErrInvalidInput Error = Error("invalid input")

ErrInvalidInput indicates malformed input. These errors are not generally retriable.

const ErrInvalidRuntimeType Error = Error("invalid type at runtime")

ErrInvalidRuntimeType signals a type error encountered at runtime. Typically included as a component in an aggregate invariant violation error.

const ErrInvariantViolation Error = Error("invariant violation")

ErrInvariantViolation is the root error of the error object that is the content of all panics produced by the Invariant helper.

const ErrLimitExceeded Error = Error("limit exceeded")

ErrLimitExceeded is a constant sentinel error that indicates that a limit has been exceeded. These are generally retriable.

const ErrMalformedConfiguration Error = Error("malformed configuration")

ErrMalformedConfiguration indicates a configuration object that has failed validation.

const ErrNotImplemented Error = Error("not implemented")

ErrNotImplemented indicates an unfinished implementation. These errors are not generally retriable.

const ErrRecoveredPanic Error = Error("recovered panic")

ErrRecoveredPanic is at the root of any error returned by a function in the fun package that recovers from a panic.

func (Error) Err added in v0.10.4

func (e Error) Err() error

Err returns the Error object as an error object (e.g. that implements the error interface.) Provided for more ergonomic conversions.

func (Error) Error

func (e Error) Error() string

Error implements the error interface for ConstError.

func (Error) Is

func (e Error) Is(err error) bool

Is Satisfies the Is() interface without using reflection.

Jump to

Keyboard shortcuts

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