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 IsInvalidParams(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
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 IsInvalidParams ¶
IsInvalidParams returns true if this is an invalid params 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/m3x/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 (MultiError) Add ¶
func (e MultiError) Add(err error) MultiError
Add adds an error returns a new MultiError object.
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) 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.