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 ¶
var Errorf = fmt.Errorf
Errorf is an alternate spelling of fmt.Errorf.
var New = goerrors.New
New is an alternate spelling of errors.New.
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 ¶
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 ¶
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 ¶
Restartable determines if the provided error is restartable. Restartable errors include transient errors and network errors.
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 ¶
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) Error ¶
Error renders this error and its chain of underlying errors, separated by Separator.
func (*Error) ErrorSeparator ¶
ErrorSeparator renders this errors and its chain of underlying errors, separated by sep.
func (*Error) HTTPStatus ¶
HTTPStatus indicates the HTTP status that should be presented in conjunction with this error.
func (*Error) MarshalJSON ¶
MarshalJSON implements JSON marshalling for Error.
func (*Error) UnmarshalJSON ¶
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 // 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 )