Documentation ¶
Overview ¶
mainly inspired by Ben Johnson, read the following blog for details: https://middlemost.com/failure-is-your-domain/
Index ¶
- func Combine(errs []error) error
- func E(args ...interface{}) error
- func EConflict(args ...interface{}) error
- func EInternal(args ...interface{}) error
- func EInvalid(args ...interface{}) error
- func ENotFound(args ...interface{}) error
- func EPermDenied(args ...interface{}) error
- func ErrCode(err error) int
- func ErrMsg(err error) string
- func F(format string, a ...interface{}) error
- func FuncName() string
- func FuncNameWithSkip(skip int) string
- func Is(err error, class Class) bool
- func IsContextCanceled(err error) bool
- func New(text string) error
- func NewF(format string, a ...interface{}) error
- func WrapMySQLError(err error) error
- type Class
- type Error
- type Op
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Combine ¶
Combine combines multiple errors by concatenating the error messages, no logical stack trace will be preserved. Use it when you need to apply a function to an array of data, and want the process to move on even if one of them returns an error.
func E ¶
func E(args ...interface{}) error
E constructs an *Error with variable number of args, which corresponds to the Class, Msg, Op, Code and Cause fields, all args are optional.
func EPermDenied ¶
func EPermDenied(args ...interface{}) error
func ErrCode ¶
ErrCode returns the ErrCode of the first error along the chain, otherwise returns -1.
func ErrMsg ¶
ErrMsg returns the first human-readable message along the chain, otherwise returns a default generic message.
func F ¶
F formats according to a format specifier and returns the string as a value that satisfies error. Deprecated: Use NewF instead.
func FuncNameWithSkip ¶
func Is ¶
Is determines whether the given error has the code along the chain, only the first non-empty Class encountered is considered.
func IsContextCanceled ¶
func WrapMySQLError ¶
Types ¶
type Class ¶
type Class string
const ( Conflict Class = "conflict" // Action cannot be performed Internal Class = "internal" // Internal error Invalid Class = "invalid" // Validation failed NotFound Class = "not_found" // Entity does not exist PermDenied Class = "permission_denied" // Does not have permission Other Class = "other" // Unclassified error )
type Error ¶
type Error struct { // For application/machine Class Class // For users & operators, see methods ErrMsg (users) and Error (operators) Msg string // For operators Op Op // logical operation Code int // error code, which identifies an user-defined error Cause error // error from lower level }
Error defines a standard application error.