Documentation ¶
Overview ¶
Package errors helps with propogating error messages up the call stack. When unhandled, the errors.Error struct prints the wrapped error message, the error cause and its context (the error being handled when the errors.Error.Err error was produced).
Index ¶
- func Aggregate(errs ...error) error
- func As(err error, target interface{}) bool
- func Cause(err error) error
- func Is(err, target error) bool
- func New(text string) error
- func WrapDeferred(pe *error, deferred func() error)
- type AnyType
- type Concurrent
- type Error
- func CreateError(err, cause, context error, skip int) Error
- func Errorf(format string, args ...interface{}) Error
- func ErrorfWithCause(cause error, format string, args ...interface{}) Error
- func ErrorfWithCauseAndContext(cause, context error, format string, args ...interface{}) Error
- func ErrorfWithContext(context error, format string, args ...interface{}) Error
- type Errors
- type Message
- type UnexpectedType
- type ValueError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aggregate ¶
Aggregate multiple errors together into a single error. Any nil errors are ommitted. Any aggregate errors are "flattened" into this error.
func Cause ¶
Cause gets the root cause of the given error. If the error is an errors.Error or *errors.Error, Cause attempts to recursively unpack the errors.Error.Cause until it gets to a Cause that is not an errors.Error or *errors.Error.
func New ¶
New calls the Go errors package's New function so that you don't have to import both packages.
func WrapDeferred ¶
WrapDeferred wraps a deferred function to ensure its returned error value isn't discarded.
Types ¶
type AnyType ¶
type AnyType []interface{}
AnyType is used in TypeError to indicate that the expected type is any of the given types.
type Concurrent ¶
type Concurrent struct {
// contains filtered or unexported fields
}
Concurrent represents a collection of errors from concurrent Goroutines.
func (*Concurrent) Add ¶
func (e *Concurrent) Add(errs ...error)
Add one or more errors to the Concurrent collection
func (*Concurrent) Err ¶
func (e *Concurrent) Err() error
Err bundles the errors in the Concurrent slice together and returns a single error. If there are no errors in the Concurrent slice, a nil error is returned.
type Error ¶
type Error struct { // Err contains the error message that's being wrapped. Err error // Cause contains an error value that directly resulted in Err being // returned Cause error // Context contains the error value that was being handled when Err // was generated Context error // contains filtered or unexported fields }
Error bundles a builtin error with its causing error (Cause) or the error that was being handled at the time that the Err error occurred (Context).
This API attempts to match that of Python's __cause__ and __context__ Exception attributes.
func CreateError ¶
CreateError creates and returns an Error object after initializing its program counters slice starting at the frame specified by skip where a value of 0 will start from the caller of CreateError
func ErrorfWithCause ¶
ErrorfWithCause creates an Error with a formatted error string and then states the error's cause within an Error struct.
func ErrorfWithCauseAndContext ¶
ErrorfWithCauseAndContext creates an Error with a formatted error string and then states the error's context within an Error struct.
func ErrorfWithContext ¶
ErrorfWithContext creates an Error with a formatted error string and then states the error's context within an Error struct.
type Message ¶
type Message struct { // Fmt holds a string with its formatting parameters Fmt string // Args are the parameters to the Fmt string in the message Args []interface{} }
Message defines an error message with parameters
type UnexpectedType ¶
type UnexpectedType struct { // Message contains the error message value. Message // Expected contains a value of the expected type. It's value may // or may not mean anything depending on the message included with // the error, but its type actually matters and is included in the // error message. // // If Expected's value's type is AnyType, then error messages state // that the expected type is any of the given slice of Expected interface{} // Actual contains a value of the expected type. It's value may // or may not mean anything depending on the message included with // the error, but its type actually matters and is included in the // error message. Actual interface{} // contains filtered or unexported fields }
UnexpectedType is returned when a value is received in a context where a value of another type was expected.
func NewUnexpectedType ¶
func NewUnexpectedType(expected, actual interface{}) *UnexpectedType
NewUnexpectedType returns an UnexpectedType error from the given pair of values.
type ValueError ¶
type ValueError struct {
Message
}