errors

package module
v0.0.0-...-c0cc067 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: Unlicense Imports: 9 Imported by: 12

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(errs ...error) error

Aggregate multiple errors together into a single error. Any nil errors are ommitted. Any aggregate errors are "flattened" into this error.

func As

func As(err error, target interface{}) bool

As forwards the call to the go errors package.

func Cause

func Cause(err error) error

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 Is

func Is(err, target error) bool

Is forwards the call to the go errors package.

func New

func New(text string) error

New calls the Go errors package's New function so that you don't have to import both packages.

func WrapDeferred

func WrapDeferred(pe *error, deferred func() error)

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

func CreateError(err, cause, context error, skip int) Error

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 Errorf

func Errorf(format string, args ...interface{}) Error

Errorf returns an error message without a Cause or Context

func ErrorfWithCause

func ErrorfWithCause(cause error, format string, args ...interface{}) Error

ErrorfWithCause creates an Error with a formatted error string and then states the error's cause within an Error struct.

func ErrorfWithCauseAndContext

func ErrorfWithCauseAndContext(cause, context error, format string, args ...interface{}) Error

ErrorfWithCauseAndContext creates an Error with a formatted error string and then states the error's context within an Error struct.

func ErrorfWithContext

func ErrorfWithContext(context error, format string, args ...interface{}) Error

ErrorfWithContext creates an Error with a formatted error string and then states the error's context within an Error struct.

func (Error) As

func (e Error) As(target interface{}) bool

func (Error) Error

func (e Error) Error() string

Error implements the builtin error interface that includes information about the Err Cause and the Context.

func (Error) Is

func (e Error) Is(err error) bool

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

func (Errors) As

func (es Errors) As(target interface{}) bool

func (Errors) Error

func (es Errors) Error() string

func (Errors) Is

func (es Errors) Is(target error) bool

func (Errors) Unwrap

func (es Errors) Unwrap() error

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

func (Message) Error

func (m Message) Error() string

Error implements the error interface so that printing strings formats the arguments.

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
}

Jump to

Keyboard shortcuts

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