Documentation ¶
Index ¶
- Variables
- func Details(e error) string
- func HTTPCode(e error) int
- func Is(e error, originals ...error) bool
- func Location(e error) (file string, line int)
- func Marshal(err error) ([]byte, error)
- func SourceLine(e error) string
- func Stack(e error) []uintptr
- func Stacktrace(e error) string
- func ToModel(err error) *models.Error
- func Unwrap(e error) error
- func UserMessage(e error) string
- func Value(e error, key interface{}) interface{}
- func Values(e error) map[interface{}]interface{}
- type Err
- func (e *Err) Append(msg string) Error
- func (e *Err) Appendf(format string, args ...interface{}) Error
- func (e *Err) Error() string
- func (e *Err) Here() Error
- func (e *Err) Marshal() ([]byte, error)
- func (e *Err) Prepend(msg string) Error
- func (e *Err) Prependf(format string, args ...interface{}) Error
- func (e *Err) WithField(key, value interface{}) Error
- func (e *Err) WithHTTPCode(code int) Error
- func (e *Err) WithMessage(msg string) Error
- func (e *Err) WithMessagef(format string, a ...interface{}) Error
- func (e *Err) WithStackSkipping(skip int) Error
- func (e *Err) WithUserMessage(msg string) Error
- func (e *Err) WithUserMessagef(format string, args ...interface{}) Error
- func (e *Err) WithValue(key, value interface{}) Error
- func (e *Err) Wrap(err error) Error
- type Error
- func Append(e error, msg string) Error
- func Appendf(e error, format string, args ...interface{}) Error
- func Errorf(format string, a ...interface{}) Error
- func Here(e error) Error
- func New(cat string, msgi ...interface{}) Error
- func Prepend(e error, msg string) Error
- func Prependf(e error, format string, args ...interface{}) Error
- func WithField(e error, key, value interface{}) Error
- func WithHTTPCode(e error, code int) Error
- func WithMessage(e error, msg string) Error
- func WithMessagef(e error, format string, a ...interface{}) Error
- func WithUserMessage(e error, msg string) Error
- func WithUserMessagef(e error, format string, args ...interface{}) Error
- func WithValue(e error, key, value interface{}) Error
- func Wrap(e error) Error
- func WrapSkipping(e error, skip int) Error
Constants ¶
This section is empty.
Variables ¶
var MaxStackDepth = 50
The maximum number of stackframes on any error.
Functions ¶
func HTTPCode ¶
Convert an error to an http status code. All errors map to 500, unless the error has an http code attached.
func SourceLine ¶
SourceLine returns the string representation of Location's result or an empty string if there's no stracktrace.
func Stacktrace ¶
Returns the error's stacktrace as a string formatted the same way as golangs runtime package. If e has no stacktrace, returns an empty string.
func Unwrap ¶
Return the innermost underlying error. Only useful in advanced cases, like if you need to cast the underlying error to some type to get additional information from it.
func UserMessage ¶
Return the end-user safe message. Returns empty if not set
Types ¶
type Err ¶
type Err struct { Err error `json:"error"` Key interface{} `json:"key"` Value interface{} `json:"value"` }
func (*Err) Append ¶
Append a message after the current error message, in the format "original: new"
func (*Err) Appendf ¶
Append a message after the current error message, in the format "original: new"
func (*Err) Error ¶
implements golang's error interface returns the message value if set, otherwise delegates to inner error
func (*Err) Prepend ¶
Prepend a message after the current error message, in the format "new: original"
func (*Err) Prependf ¶
Prepend a message after the current error message, in the format "new: original"
func (*Err) WithHTTPCode ¶
return a new error with an http status code attached
func (*Err) WithMessage ¶
return a new error with a new message
func (*Err) WithMessagef ¶
return a new error with a new formatted message
func (*Err) WithStackSkipping ¶
return a new error with a new stack capture
func (*Err) WithUserMessage ¶
Add a message which is suitable for end users to see
func (*Err) WithUserMessagef ¶
Add a message which is suitable for end users to see
type Error ¶
type Error interface { error Appendf(format string, args ...interface{}) Error Append(msg string) Error Prepend(msg string) Error Prependf(format string, args ...interface{}) Error WithMessage(msg string) Error WithMessagef(format string, args ...interface{}) Error WithUserMessage(msg string) Error WithUserMessagef(format string, args ...interface{}) Error WithValue(key, value interface{}) Error WithField(key, value interface{}) Error Here() Error Wrap(error) Error WithStackSkipping(skip int) Error WithHTTPCode(code int) Error }
func Errorf ¶
Create a new error with a formatted message and a stack. The equivalent of golang's fmt.Errorf()
func Here ¶
Attach a new stack to the error, at the call site of Here(). Useful when returning copies of exported package errors
func WithField ¶
Add a context an error. If the key was already set on e, the new value will take precedence.
func WithHTTPCode ¶
Return an error with an http code attached.
func WithMessage ¶
Override the message of error. The resulting error's Error() method will return the new message
func WithMessagef ¶
Same as WithMessage(), using fmt.Sprint()
func WithUserMessage ¶
Add a message which is suitable for end users to see
func WithUserMessagef ¶
Add a message which is suitable for end users to see
func WithValue ¶
Add a context an error. If the key was already set on e, the new value will take precedence.
func WrapSkipping ¶
Cast e to *Error, or wrap e in a new *Error with stack Skip `skip` frames (0 is the call site of `WrapSkipping()`)