Documentation
¶
Overview ¶
Package errors mirrors the standard golang "errors" module. Manipulate errors and provide stack trace information. All golang codes should using this errors package.
Index ¶
- Constants
- func DefaultError(e Error) string
- func Message(err interface{}) string
- func StackTrace() (current, context string)
- type Error
- func New(msg string) Error
- func NewByCode(code int, msg string) Error
- func Newf(format string, args ...interface{}) Error
- func NewfByCode(code int, format string, args ...interface{}) Error
- func Wrap(err error, msg string) Error
- func WrapByCode(code int, err error, msg string) Error
- func Wrapf(err error, format string, args ...interface{}) Error
- func WrapfByCode(code int, err error, format string, args ...interface{}) Error
Constants ¶
const (
DefaultCode = -1
)
Default value if the error code is not defined. The error code is DefaultCode if Error was created by New, Newf, Wrap, Wrapf.
Variables ¶
This section is empty.
Functions ¶
func DefaultError ¶
A default implementation of the Error method of the error interface.
func Message ¶
func Message(err interface{}) string
This returns the error string without stack trace information.
func StackTrace ¶
func StackTrace() (current, context string)
This returns the current stack trace string.
Types ¶
type Error ¶
type Error interface { // This returns the error message without the stack trace. Message() string // This returns the stack trace without the error message. Stack() string // This returns the stack trace's context. Context() string // This returns the error code. // If the error code is not pre-defined, return is DefaultCode. Code() int // This returns the wrapped error. Nil if not wrap another error. Inner() error // Implements the built-in error interface. Error() string }
Error interface exposes additional information about the error.
func New ¶
This returns a new baseError initialized with the given message and the current stack trace.
func NewByCode ¶
This returns a new baseError initialized with the given message, error code and the current stack trace.
func NewfByCode ¶
Same as NewByCode, but with fmt.Printf-style parameters.
func WrapByCode ¶
Wraps another error in a new baseError with error code information.