Documentation ¶
Overview ¶
Package werror provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.
Index ¶
- func Aborted(msg string, wrappers ...Wrapper) error
- func Append(err error, msg string, wrappers ...Wrapper) error
- func Appendf(err error, format string, args ...interface{}) error
- func As(err error, target interface{}) bool
- func Cause(err error) error
- func Code(err error) codes.Code
- func Details(err error) string
- func Forbidden(msg string, wrappers ...Wrapper) error
- func Format(s fmt.State, verb rune, err error)
- func ID(err error) string
- func Internal(msg string, wrappers ...Wrapper) error
- func InvalidArgument(msg string, wrappers ...Wrapper) error
- func Is(err, target error) bool
- func Lookup(err error, key interface{}) (interface{}, bool)
- func New(msg string, wrappers ...Wrapper) error
- func NotFound(msg string, wrappers ...Wrapper) error
- func Prepend(err error, msg string, wrappers ...Wrapper) error
- func Prependf(err error, format string, args ...interface{}) error
- func Set(err error, key, value interface{}) error
- func Unauthenticated(msg string, wrappers ...Wrapper) error
- func Unavailable(msg string, wrappers ...Wrapper) error
- func Unwrap(err error) error
- func Value(err error, key interface{}) interface{}
- func Values(err error) map[interface{}]interface{}
- func Wrap(err error, wrappers ...Wrapper) error
- type ErrKey
- type Wrapper
- func AppendMessage(msg string) Wrapper
- func AppendMessagef(format string, args ...interface{}) Wrapper
- func PrependMessage(msg string) Wrapper
- func PrependMessagef(format string, args ...interface{}) Wrapper
- func WithCause(err error) Wrapper
- func WithCode(code codes.Code) Wrapper
- func WithID(msg string) Wrapper
- func WithValue(key, value interface{}) Wrapper
- type WrapperFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Appendf ¶
Appendf is a convenience function for the AppendMessagef wrapper. The args can be format arguments mixed with Wrappers.
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.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.
func Code ¶
Code converts an error to gRPC status code. All errors map to Internal, unless the error has code attached. If err is nil, returns OK.
func Details ¶
Details returns err.Error() and any additional details. The details of each error cause chain will also be printed.
func Format ¶
Format adapts errors to fmt.Formatter interface. It's intended to be used help error impls implement fmt.Formatter, e.g.:
func (e *myErr) Format(f fmt.State, verb rune) { Format(f, verb, e) }
func InvalidArgument ¶
func Is ¶
Is reports whether any error in err's chain matches target.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
func Lookup ¶
Lookup returns the value for the key, and a boolean indicating whether the value was set. Will not search causes.
func Prependf ¶
Prependf is a convenience function for the PrependMessagef wrapper. The args can be format arguments mixed with Wrappers.
func Set ¶
Set wraps an error with a key/value pair. This is the simplest form of associating a value with an error. It is mainly intended as a primitive for writing Wrapper implementations.
func Unauthenticated ¶
func Unavailable ¶
func Unwrap ¶
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.
func Value ¶
func Value(err error, key interface{}) interface{}
Value returns the value for key, or nil if not set. Will not search causes.
Types ¶
type Wrapper ¶
type Wrapper interface { // Wrap returns a new error, wrapping the argument, and typically adding some context information. Wrap(err error) error }
Wrapper knows how to wrap errors with context information.
func AppendMessage ¶
AppendMessage a message after the current error message, in the format "original: new".
func AppendMessagef ¶
AppendMessagef is the same as AppendMessage, but with a formatted message.
func PrependMessage ¶
PrependMessage a message before the current error message, in the format "new: original".
func PrependMessagef ¶
PrependMessagef is the same as PrependMessage, but with a formatted message.
func WithCause ¶
WithCause sets one error as the cause of another error. This is useful for associating errors from lower API levels with sentinel errors in higher API levels. errors.Is() and errors.As() will traverse both the main chain of error wrappers, and down the chain of causes.
type WrapperFunc ¶
WrapperFunc implements Wrapper.
func (WrapperFunc) Wrap ¶
func (w WrapperFunc) Wrap(err error) error
Wrap implements the Wrapper interface.