errors

package
v0.0.0-...-0f4c570 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package errors provides a standard error definition for use in Reflow. Each error is assigned a class of error (kind) and an operation with optional arguments. Errors may be chained, and thus can be used to annotate upstream errors.

Errors may be serialized to- and deserialized from JSON, and thus shipped over network services.

Package errors provides functions Errorf and New as convenience constructors, so that users need import only one error package.

The API was inspired by package upspin.io/errors.

Index

Constants

This section is empty.

Variables

View Source
var Errorf = fmt.Errorf

Errorf is an alternate spelling of fmt.Errorf.

New is an alternate spelling of errors.New.

View Source
var Separator = ":\n\t"

Separator is inserted between chained errors while rendering. The default value (":\n\t") is inteded for interactive tools. A server can set this to a different value to be more log friendly.

Functions

func E

func E(args ...interface{}) error

E is used to construct errors. E constructs errors from a set of arguments; each of which must be one of the following types:

string
	The first string argument is taken as the error's Op; subsequent
	arguments are taken as the error's Arg.
digest.Digest
	Taken as an Arg.
Kind
	Taken as the error's Kind.
error
	Taken as the error's underlying error.

If a Kind is provided, there is no further processing. If not, and an underlying error is provided, E attempts to interpret it as follows: (1) If the underlying error is another *Error, and there is no Kind argument, the Kind is inherited from the *Error. (2) If the underlying error has method Timeout() bool, it is invoked, and if it returns true, the error's kind is set to Timeout. (3) If the underlying error has method Temporary() bool, it is invoked, and if it returns true, the error's kind is set to Temporary. (4) If the underyling error is context.Canceled, the error's kind is set to Canceled. (5) If the underlying error is an os.IsNotExist error, the error's kind is set to NotExist.

func Is

func Is(kind Kind, err error) bool

Is tells whether an error has a specified kind, except for the indeterminate kind Other. In the case an error has kind Other, the chain is traversed until a non-Other error is encountered.

func Match

func Match(err1, err2 error) bool

Match compares err1 with err2. If err1 has type Kind, Match reports whether err2's Kind is the same, otherwise, Match checks that every nonempty field in err1 has the same value in err2. If err1 is an *Error with a non-nil Err field, Match recurs to check that the two errors chain of underlying errors also match.

func Restartable

func Restartable(err error) bool

Restartable determines if the provided error is restartable. Restartable errors include transient errors and network errors.

func Transient

func Transient(err error) bool

Transient tells whether error err is likely transient, and thus may be usefully retried.

Types

type Error

type Error struct {
	// Kind is the error's type.
	Kind Kind
	// Op is a one-word description of the operation that errored.
	Op string
	// Arg is an (optional) list of arguments to the operation.
	Arg []string
	// Err is this error's underlying error: this error is caused
	// by Err.
	Err error
}

Error defines a Reflow error. It is used to indicate an error associated with an operation (and arguments), and may wrap another error.

Errors should be constructed by errors.E.

func Recover

func Recover(err error) *Error

Recover recovers any error into an *Error. If the passed-in Error is already an error, it is simply returned; otherwise it is wrapped.

func (*Error) Copy

func (e *Error) Copy() *Error

Copy creates a shallow copy of Error e.

func (*Error) Error

func (e *Error) Error() string

Error renders this error and its chain of underlying errors, separated by Separator.

func (*Error) ErrorSeparator

func (e *Error) ErrorSeparator(sep string) string

ErrorSeparator renders this errors and its chain of underlying errors, separated by sep.

func (*Error) HTTPStatus

func (e *Error) HTTPStatus() int

HTTPStatus indicates the HTTP status that should be presented in conjunction with this error.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON marshalling for Error.

func (*Error) Temporary

func (e *Error) Temporary() bool

Temporary tells whether this error is temporary.

func (*Error) Timeout

func (e *Error) Timeout() bool

Timeout tells whether this error is a timeout error.

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(b []byte) error

UnmarshalJSON implements JSON unmarshalling for Error.

type Kind

type Kind int

Kind denotes the type of the error. The error's kind is used to render the error message and also for interpretation.

const (
	// Other denotes an unknown error.
	Other Kind = iota
	// Canceled denotes a cancellation error.
	Canceled
	// Timeout denotes a timeout error.
	Timeout
	// Temporary denotes a transient error.
	Temporary
	// NotExist denotes an error originating from a nonexistant resource.
	NotExist
	// NotAllowed denotes a permissions error.
	NotAllowed
	// NotSupported indicates the operation was not supported.
	NotSupported
	// TooManyTries indicates that the operation was retried too many times.
	TooManyTries
	// Integrity denotes an integrity check error.
	Integrity
	// ResourcesExhausted indicates that there were insufficient resources.
	ResourcesExhausted
	// Eval denotes an evaluation error.
	Eval
	// Unavailable denotes that a resource is temporarily unavailable.
	Unavailable
	// Fatal denotes an unrecoverable error.
	Fatal
	// Invalid indicates an invalid state or data.
	Invalid
	// Net indicates a networking error.
	Net
	// Precondition indicates that a precondition was not met.
	Precondition
)

func (Kind) String

func (k Kind) String() string

String renders a human-readable description of kind k.

Jump to

Keyboard shortcuts

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