Documentation ¶
Overview ¶
Package errors provides error and error wrapping facilities that allow for the easy reporting of call stacks and structured error annotations.
Index ¶
- func Cause(err error) (stack CallStack, wraps []*Base, cause error)
- func HTTPStatus(err error) (status int, ok bool)
- func New(text string) error
- type Base
- type Call
- type CallStack
- type Fields
- type HTTPError
- func BadRequest(fields Fields, text string) *HTTPError
- func Conflict(fields Fields, text string) *HTTPError
- func Forbidden(fields Fields, text string) *HTTPError
- func InternalError(fields Fields, text string) *HTTPError
- func NewHTTPError(status int, text string) *HTTPError
- func NotFound(fields Fields, text string) *HTTPError
- func PaymentRequired(fields Fields, text string) *HTTPError
- type Location
- type Wrapped
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cause ¶
Cause checks if the passed in error is a Wrapped. If so, it will extract & return information about all the wrapped errors inside. It will return the CallStack of cause, if it supports the errors.Stack() interface, or the innermost wrap (which should be the closest wrap to cause.) If error is not a wrapped, cause is same as input err.
func HTTPStatus ¶
HTTPStatus is a convenience checker for a (possibly wrapped) HTTPStatus interface error. If err doesn't support the HTTPStatus interface, it will default to either StatusOK or StatusInternalServerError as appropriate.
Types ¶
type Base ¶
Base is an error type that supports capturing the call stack at creation time, and storing separate text & data to allow structured logging. While it could be used directly, it may make more sense as an anonymous inside a package/application specific error struct.
func (*Base) AddFields ¶
AddFields allows a Error message to be further annotated with a set of key,values, to add more context when inspecting Error messages.
func (*Base) Location ¶
Location returns the location info (file, line, ...) for the place where this Error error was created.
func (*Base) MarshalJSON ¶
MarshalJSON creates a JSON representation of a Error.
type Call ¶
Call holds a call frame
func (Call) Location ¶
Location uses the gostack package to construct file, line, and other info about this call.
func (Call) MarshalJSON ¶
MarshalJSON returns the JSON representation.
type CallStack ¶
type CallStack []Call
CallStack is a convenience alias for a call stack.
func CurrentCallStack ¶
CurrentCallStack returns the call stack, skipping the specified depth of calls.
type HTTPError ¶
HTTPError provides an easy way to specify the http status code equivalent for an error at error creation time, as well as inheriting the useful features from Base (call stacks, structured text & data).
func BadRequest ¶
BadRequest is returned when a request did not pass validation, or is in appropriate for the state of the resource it would affect.
func Conflict ¶
Conflict is returned when request could not be completed due to a conflict with the current state of the resource.
func Forbidden ¶
Forbidden is returned if the requesting user does not have the required permissions for a request.
func InternalError ¶
InternalError should only be returned if no other specific error applies.
func NewHTTPError ¶
NewHTTPError constructs an error with the given http status.
func PaymentRequired ¶
PaymentRequired is returned if the requested resource must be purchased.
func (*HTTPError) HTTPStatus ¶
HTTPStatus returns the appropriate http status code for this error.
func (*HTTPError) With ¶
With allows additional structured data fields to be added to this HTTPError.
func (*HTTPError) WithStatus ¶
WithStatus allows setting the http status.
type Location ¶
Location is the parsed file, line, and other info we can determine from a specific gostack.Call.
type Wrapped ¶
type Wrapped struct { *Base // contains filtered or unexported fields }
Wrapped provides a way to add additional context when passing back an error to a caller. It inherits the useful features from Base (call stacks, structured text & data).
func WithMessage ¶
WithMessage takes an originating cause and text description, returning a wrapped error with the text and stack.
func WithStack ¶
WithStack takes an originating cause and returns a wrapped error that just records the stack.
func Wrap ¶
Wrap takes an originating "cause" error and annotates it just with the source file & line of the wrap point.
func Wrapf ¶
Wrapf takes an originating "cause" error and annotates it with text and the source file & line of the wrap point.