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 ¶
- func As(err error, target any) bool
- func Cast(e any) error
- func GetTime(err error) time.Time
- func If(cond bool, err error) error
- func Is(err error, targets ...error) bool
- func IsError(err error) bool
- func IsExpiredContext(err error) bool
- func IsInvariantViolation(r any) bool
- func IsOk(err error) bool
- func IsTerminating(err error) bool
- func New(str string) error
- func NewWithTime(e string) error
- func Unwind(in error) []error
- func Unwrap(err error) error
- func When(cond bool, val string) error
- func Whenf(cond bool, tmpl string, args ...any) error
- func WithTime(err error) error
- func Wrap(err error, annotation string) error
- func Wrapf(err error, tmpl string, args ...any) error
- type Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTime ¶
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
If constructs an ers.Error-typed error value IF the conditional is true, and returns nil otherwise.
func Is ¶
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 IsExpiredContext ¶ added in v0.10.5
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 ¶
IsInvariantViolation returns true if the argument is or resolves to ers.ErrInvariantViolation.
func IsOk ¶ added in v0.12.0
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 ¶
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 NewWithTime ¶
NewWithTime creates a new error object with the provided string.
func Unwind ¶
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 ¶
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
When constructs an error from the provided string when the condition is true, and returns nil otherwise.
func Whenf ¶ added in v0.10.4
Whenf constructs an error (using fmt.Errorf) IF the conditional is true, and returns nil otherwise.
func WithTime ¶
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 ¶
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.
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.
ErrContainerClosed is returned for operations against a container that has been closed or finished.
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.
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.
ErrImmutabilityViolation is an returned by some operations or invariant violations when an operation attempts to modify logically immutable value.
ErrInvalidInput indicates malformed input. These errors are not generally retriable.
ErrInvalidRuntimeType signals a type error encountered at runtime. Typically included as a component in an aggregate invariant violation error.
ErrInvariantViolation is the root error of the error object that is the content of all panics produced by the Invariant helper.
ErrLimitExceeded is a constant sentinel error that indicates that a limit has been exceeded. These are generally retriable.
ErrMalformedConfiguration indicates a configuration object that has failed validation.
ErrNotImplemented indicates an unfinished implementation. These errors are not generally retriable.
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
Err returns the Error object as an error object (e.g. that implements the error interface.) Provided for more ergonomic conversions.