Documentation ¶
Overview ¶
This package defines several functions that help when working with errors. It provides a way to have consistent, descriptive errors.
Index ¶
- Variables
- func AppendError(errs ...error) error
- func ArrayDimsArgree[N any, P any](l []N, r []P) error
- func Assert(op func() error)
- func ChainedErrorOps(ops ...func(results ...any) (any, error)) error
- func Unwrap(err error) error
- func Wrap(origErr error, fmtStr string, vals ...any) error
- func WrapValueList(origErr error, description string, valsList []WrapListVal) error
- type WrapListVal
Constants ¶
This section is empty.
Variables ¶
var DimensionsDoNotAgree = errors.New("Dimensions do not agree")
var IncorrectType = errors.New("An incorrect type was received.") // Used when only one type is accepted
var InvalidValue = errors.New("The supplied value is not valid in the supplied context")
var MultipleErrorsOccurred = errors.New("Multiple errors have occurred")
var UnsupportedType = errors.New("The type of the received value was not valid") // Used when multiple types are accepted
var ValOutsideRange = errors.New("The specified value is outside the allowed range")
Functions ¶
func AppendError ¶
Given a list of errors it will append them with a predetermined format, as shown below.
<original first error> |- <wrapped information> ... <original nth error> |- <wrapped information>
This allows for consistent error formatting. Special cases are as follows:
- All supplied errors are nil: The returned value will be nil.
- Only one of the supplied errors is nil: The returned value will be the error that is not nil.
- Multiple errors are not nil: The returned error will be a MultipleErrorsOccurred error with all of the sub-errors wrapped in it following the above format.
func ArrayDimsArgree ¶
func Assert ¶
func Assert(op func() error)
A run-time assert function that will panic if the given operation function returns an error. The panic will be given the error that the operation function returns. If the operation function returns nil then it will not panic.
func ChainedErrorOps ¶
Will continue to call the provided operation functions (ops) in the order that they were given until one of them returns an error. The return values of all previous operations will be passed as argument to the current operation in the order that the values were generated. Index 0 represents the return value from the first operation function, index 1 represent the return value from the second operation, etc.
func Unwrap ¶
Unwraps an error. A simple helper function to provide a clean error interface in this module.
func Wrap ¶
Wraps an error with a predetermined format, as shown below.
<original error> |- <wrapped information>
This allows for consistent error formatting.
func WrapValueList ¶
func WrapValueList( origErr error, description string, valsList []WrapListVal, ) error
Wraps an error with a predetermined format, as shown below,
<original error> |- <description> |- value1 name (value1 type): value1 |- value2 name (value2 type): value2
This allows for consistent error formatting.