Documentation
¶
Overview ¶
Package errors contains utilties for wrapping and pretty printing mapping errors. The intended use is to Wrap errors with information as they bubble back up the stack. For information on this paradigm, see https://blog.golang.org/go1.13-errors
Index ¶
- Constants
- func FnLocationf(format string, formatArgs ...interface{}) error
- func Locationf(format string, formatArgs ...interface{}) error
- func Recover(operationName string, handler func(error))
- func SuffixNumber(num int) string
- func Wrap(outter, inner error) error
- type NotFoundError
- type ProtoLocation
Constants ¶
const ( // FunctionStartPrefix is the prefix to use for formatting error locations that indicate the start // of the function. FunctionStartPrefix = "" // FunctionStartSuffix is the suffix to use for formatting error locations that indicate the start // of the function. FunctionStartSuffix = "\n" // DefaultPrefix is the prefix to use for formatting error locations (that are not function // starts). DefaultPrefix = "\t" // DefaultSuffix is the suffix to use for formatting error locations (that are not function // starts). DefaultSuffix = "" )
Variables ¶
This section is empty.
Functions ¶
func FnLocationf ¶
FnLocationf returns a string based implementation of an Error to use as a wrapper, similar to fmt.Sprintf.
func Locationf ¶
Locationf returns a string based implementation of an Error to use as a wrapper, similar to fmt.Sprintf.
func Recover ¶
Recover is a deferrable function that recovers a panic, and passes that back to the given handler (which should probably assign the error return value of the function within which this is deferred).
func SuffixNumber ¶
SuffixNumber adds an English ordinal indicator to the end of the given number. For example, 1 -> "1st", 54 -> "54th"
func Wrap ¶
Wrap is the opposite of Go's errors.Unwrap, and a utility method for formatting wrapped errors. This implementation puts the inner error at the top, followed by a new line followed by the outter error; i.e. it is a thin wrapper of fmt.Errorf's %w verb. Wrap can be called with a nil inner error, which will subsequently return nil.
Types ¶
type NotFoundError ¶
type NotFoundError struct {
Msg string
}
NotFoundError is returned when fetch encounters a 404 error.
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type ProtoLocation ¶
type ProtoLocation struct {
// contains filtered or unexported fields
}
ProtoLocation is an implementation of error that generates locations from proto messages.
func NewProtoLocation ¶
func NewProtoLocation(msg, parent proto.Message) ProtoLocation
NewProtoLocation generates a ProtoLocation based on a given message and its parent message. The parent message is used to derive a name for the proto message value (i.e. based on which field in the parent contains the given message value).
func NewProtoLocationf ¶
func NewProtoLocationf(msg proto.Message, nameFormat string, nameFormatArgs ...interface{}) ProtoLocation
NewProtoLocationf generates a ProtoLocation based on a given message and a format string with format arguments. The format string is used as a name for the proto message and the message itself is used for its type.
func (ProtoLocation) Error ¶
func (p ProtoLocation) Error() string
func (ProtoLocation) String ¶
func (p ProtoLocation) String() string