customerr

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

This package defines several functions that help when working with errors. It provides a way to have consistent, descriptive errors.

Index

Constants

This section is empty.

Variables

View Source
var DimensionsDoNotAgree = errors.New("Dimensions do not agree")
View Source
var IncorrectType = errors.New("An incorrect type was received.") // Used when only one type is accepted
View Source
var InvalidValue = errors.New("The supplied value is not valid in the supplied context")
View Source
var MultipleErrorsOccurred = errors.New("Multiple errors have occurred")
View Source
var UnsupportedType = errors.New("The type of the received value was not valid") // Used when multiple types are accepted
View Source
var ValOutsideRange = errors.New("The specified value is outside the allowed range")

Functions

func AppendError

func AppendError(errs ...error) error

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 ArrayDimsArgree[N any, P any](l []N, r []P) error

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

func ChainedErrorOps(ops ...func(results ...any) (any, error)) error

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

func Unwrap(err error) error

Unwraps an error. A simple helper function to provide a clean error interface in this module.

func Wrap

func Wrap(origErr error, fmtStr string, vals ...any) error

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.

Types

type WrapListVal

type WrapListVal struct {
	ItemName string
	Item     any
}

Jump to

Keyboard shortcuts

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