errors

package
v0.15.17-hotfix.5 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 3 Imported by: 118

Documentation

Overview

Package errors provides utilities for working with different types errors.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstError

func FirstError(errs ...error) error

FirstError returns the first non nil error.

func GetInnerInvalidParamsError

func GetInnerInvalidParamsError(err error) error

GetInnerInvalidParamsError returns an inner invalid params error if contained by this error, nil otherwise.

func GetInnerNonRetryableError

func GetInnerNonRetryableError(err error) error

GetInnerNonRetryableError returns an inner non-retryable error if contained by this error, nil otherwise.

func GetInnerRetryableError

func GetInnerRetryableError(err error) error

GetInnerRetryableError returns an inner retryable error if contained by this error, nil otherwise.

func InnerError

func InnerError(err error) error

InnerError returns the packaged inner error if this is an error that contains another.

func IsInvalidParams

func IsInvalidParams(err error) bool

IsInvalidParams returns true if this is an invalid params error.

func IsNonRetryableError

func IsNonRetryableError(err error) bool

IsNonRetryableError returns true if this is a non-retryable error.

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError returns true if this is a retryable error.

func NewInvalidParamsError

func NewInvalidParamsError(inner error) error

NewInvalidParamsError creates a new invalid params error

func NewNonRetryableError

func NewNonRetryableError(inner error) error

NewNonRetryableError creates a new non-retryable error.

func NewRenamedError

func NewRenamedError(inner, renamed error) error

NewRenamedError returns a new error that packages an inner error with a renamed error.

func NewRetryableError

func NewRetryableError(inner error) error

NewRetryableError creates a new retryable error.

func Wrap

func Wrap(err error, msg string) error

Wrap wraps an error with a message but preserves the type of the error.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf formats according to a format specifier and uses that string to wrap an error while still preserving the type of the error.

Types

type ContainedError

type ContainedError interface {
	InnerError() error
}

ContainedError is an error with a contained error.

type Errors

type Errors []error

Errors is a slice of errors that itself is an error too.

func (Errors) Error

func (e Errors) Error() string

Error implements 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 NewMultiError

func NewMultiError() MultiError

NewMultiError creates a new MultiError object.

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) 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.

Jump to

Keyboard shortcuts

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