Documentation ¶
Overview ¶
Package errors provides utilities for working with different types errors.
Index ¶
- func FirstError(errs ...error) error
- func GetInnerInvalidParamsError(err error) error
- func GetInnerNonRetryableError(err error) error
- func GetInnerRetryableError(err error) error
- func InnerError(err error) error
- func Is(err, target error) bool
- func IsInvalidParams(err error) bool
- func IsMultiError(err error) bool
- func IsNonRetryableError(err error) bool
- func IsRetryableError(err error) bool
- func NewInvalidParamsError(inner error) error
- func NewNonRetryableError(inner error) error
- func NewRenamedError(inner, renamed error) error
- func NewRetryableError(inner error) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, format string, args ...interface{}) error
- type ContainedError
- type Errors
- type MultiError
- func (e MultiError) Add(err error) MultiError
- func (e MultiError) Contains(err error) bool
- func (e MultiError) Empty() bool
- func (e MultiError) Error() string
- func (e MultiError) Errors() []error
- func (e MultiError) FinalError() error
- func (e MultiError) LastError() error
- func (e MultiError) NumErrors() int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetInnerInvalidParamsError ¶
GetInnerInvalidParamsError returns an inner invalid params error if contained by this error, nil otherwise.
func GetInnerNonRetryableError ¶
GetInnerNonRetryableError returns an inner non-retryable error if contained by this error, nil otherwise.
func GetInnerRetryableError ¶
GetInnerRetryableError returns an inner retryable error if contained by this error, nil otherwise.
func InnerError ¶
InnerError returns the packaged inner error if this is an error that contains another.
func Is ¶ added in v1.2.0
Is checks if the error is or contains the corresponding target error. It's intended to mimic the errors.Is functionality, but also consider xerrors' MultiError / InnerError wrapping functionality.
func IsInvalidParams ¶
IsInvalidParams returns true if this is an invalid params error.
func IsMultiError ¶ added in v1.0.0
IsMultiError returns true if this is a multi-error error.
func IsNonRetryableError ¶
IsNonRetryableError returns true if this is a non-retryable error.
func IsRetryableError ¶
IsRetryableError returns true if this is a retryable error.
func NewInvalidParamsError ¶
NewInvalidParamsError creates a new invalid params error
func NewNonRetryableError ¶
NewNonRetryableError creates a new non-retryable error.
func NewRenamedError ¶
NewRenamedError returns a new error that packages an inner error with a renamed error.
func NewRetryableError ¶
NewRetryableError creates a new retryable error.
Types ¶
type ContainedError ¶
type ContainedError interface {
InnerError() error
}
ContainedError is an error with a contained error.
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError is an immutable error that packages a list of errors.
TODO(xichen): we may want to limit the number of errors included.
Example ¶
package main import ( "fmt" "strings" "github.com/m3db/m3/src/x/errors" ) func main() { multiErr := errors.NewMultiError() for i := 0; i < 3; i++ { // Perform some work which may fail. err := fmt.Errorf("error %d", i) if err != nil { // Add returns a new MultiError. multiErr = multiErr.Add(err) } } if err := multiErr.FinalError(); err != nil { msg := strings.Replace(err.Error(), "\n", "; ", -1) fmt.Println(msg) } if err := multiErr.LastError(); err != nil { fmt.Println(err) } }
Output: error 0; error 1; error 2 error 2
func GetInnerMultiError ¶ added in v1.0.0
func GetInnerMultiError(err error) (MultiError, bool)
GetInnerMultiError returns an inner multi-error error if contained by this error, nil otherwise.
func (MultiError) Add ¶
func (e MultiError) Add(err error) MultiError
Add adds an error returns a new MultiError object.
func (MultiError) Contains ¶ added in v1.2.0
func (e MultiError) Contains(err error) bool
Contains returns true if any of the errors match the provided error using the Is check.
func (MultiError) Empty ¶
func (e MultiError) Empty() bool
Empty returns true if the MultiError has no errors.
func (MultiError) Error ¶
func (e MultiError) Error() string
func (MultiError) Errors ¶ added in v0.10.0
func (e MultiError) Errors() []error
Errors returns all the errors to inspect individually.
func (MultiError) FinalError ¶
func (e MultiError) FinalError() error
FinalError returns all concatenated error messages if any.
func (MultiError) LastError ¶
func (e MultiError) LastError() error
LastError returns the last received error if any.
func (MultiError) NumErrors ¶
func (e MultiError) NumErrors() int
NumErrors returns the total number of errors.