Documentation ¶
Overview ¶
Package errors provides functions and types to define and manipulate errors. It should generally be used instead of the standard library's errors package, as it is a strict superset.
Index ¶
- func Arg(e error, name string) error
- func As(err error, target interface{}) bool
- func Errorf(f string, args ...interface{}) error
- func Is(err, target error) bool
- func IsArg(e error, names ...string) bool
- func IsStatus(e error, codes ...int) bool
- func IsTag(e error, tags ...string) bool
- func New(s string) error
- func Status(e error, code int) error
- func Tag(e error, tag string) error
- func Unwrap(err error) error
- type ArgError
- type ConstError
- type StatusError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Arg ¶
Arg returns an error that wraps e indicating an argument error for the parameter of the specified name.
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.
func Errorf ¶
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
If the format specifier includes a %w verb with an error operand, the returned error will implement an Unwrap method returning the operand. It is invalid to include more than one %w verb or to supply it with an operand that does not implement the error interface. The %w verb is otherwise a synonym for %v.
func IsArg ¶
IsArg returns true if e or any error in its chain is an ArgError marked with any of the provided parameter names, otherwise it returns false.
func IsStatus ¶
IsStatus returns true if e or any error in its chain is marked with any of the provided status codes, otherwise it returns false.
func IsTag ¶
IsTag returns true if e or any error in its chain is tagged by any of the provided tags, otherwise it returns false.
func Status ¶
Status returns an error that wraps e and marks it with the provided HTTP status code. Errors can be queried for status with IsStatus. If e is nil, it returns nil.
Types ¶
type ArgError ¶
type ArgError struct { // Name is the parameter name of the invalid argument. Name string // Err is the error wrapped by this ArgError. Err error }
ArgError is an error due to an invalid argument.
type ConstError ¶
type ConstError string
ConstError is an error string that can be defined as constant.
const ( // ErrNotMocked is returned when a method is called on a mock but no // mocked implementation was set up. ErrNotMocked ConstError = "not mocked" )
func (ConstError) Error ¶
func (e ConstError) Error() string
Error returns the error message of the ConstError, which is the constant string value itself.
type StatusError ¶
type StatusError struct { // Code is the status code associated with the error. By convention, // it should be an HTTP status code (typically in the 4xx-5xx range). Code int // Err is the error wrapped by this StatusError. Err error }
StatusError is an error marked with a status code, which by convention should be an HTTP status code indicating the type of error it wraps. E.g. 404 if a database row was not found, 409 for a unique constraint violation, 500 for a connection error, etc.
func (StatusError) Unwrap ¶
func (e StatusError) Unwrap() error
Unwrap returns the error wrapped by StatusError.