Documentation ¶
Overview ¶
Package multierr provides rich functionalities to manipulate errors.
For maintainers, please very note that, this package is quite a basic package, which SHOULD NOT import extra packages except standard packages and internal packages, to avoid cycle imports.
Index ¶
- Constants
- func Cause(err error) error
- func Code(err error) codes.Code
- func Current(err error) error
- func Equal(err, target error) bool
- func HasCode(err error, code codes.Code) bool
- func HasError(err, target error) bool
- func HasStack(err error) bool
- func Is(err, target error) bool
- func New(text string) error
- func NewCode(code codes.Code, text ...string) error
- func NewCodeSkip(code codes.Code, skip int, text ...string) error
- func NewCodeSkipf(code codes.Code, skip int, format string, args ...interface{}) error
- func NewCodef(code codes.Code, format string, args ...interface{}) error
- func NewOption(option Option) error
- func NewSkip(skip int, text string) error
- func NewSkipf(skip int, format string, args ...interface{}) error
- func NewWithOption(option Option) error
- func Newf(format string, args ...interface{}) error
- func Stack(err error) string
- func Unwrap(err error) error
- func Wrap(err error, text string) error
- func WrapCode(code codes.Code, err error, text ...string) error
- func WrapCodeSkip(code codes.Code, skip int, err error, text ...string) error
- func WrapCodeSkipf(code codes.Code, skip int, err error, format string, args ...interface{}) error
- func WrapCodef(code codes.Code, err error, format string, args ...interface{}) error
- func WrapSkip(skip int, err error, text string) error
- func WrapSkipf(skip int, err error, format string, args ...interface{}) error
- func Wrapf(err error, format string, args ...interface{}) error
- type CauseInterface
- type CodeInterface
- type CurrentInterface
- type EqualInterface
- type Error
- func (err *Error) Cause() error
- func (err *Error) Code() codes.Code
- func (err *Error) Current() error
- func (err *Error) Equal(target error) bool
- func (err *Error) Error() string
- func (err *Error) Format(s fmt.State, verb rune)
- func (err *Error) Is(target error) bool
- func (err Error) MarshalJSON() ([]byte, error)
- func (err *Error) SetCode(code codes.Code)
- func (err *Error) Stack() string
- func (err *Error) Unwrap() error
- type IsInterface
- type Option
- type StackInterface
- type UnwrapInterface
Constants ¶
const Version = "v1.0.0"
Version is the current version.
Variables ¶
This section is empty.
Functions ¶
func Code ¶
Code returns the error code of `current error`. It returns `CodeNil` if it has no error code neither it does not implement interface Code.
func Current ¶
Current creates and returns the current level error. It returns nil if current level error is nil.
func Equal ¶
Equal reports whether current error `err` equals to error `target`. Please note that, in default comparison logic for `Error`, the errors are considered the same if both the `code` and `text` of them are the same.
func HasStack ¶
HasStack checks and reports whether `err` implemented interface `multierr.StackInterface`.
func Is ¶
Is reports whether current error `err` has error `target` in its chaining errors. It is just for implements for stdlib errors.Is from Go version 1.17.
func NewCodeSkip ¶
NewCodeSkip creates and returns an error which has error code and is formatted from given text. The parameter `skip` specifies the stack callers skipped amount.
func NewCodeSkipf ¶
NewCodeSkipf returns an error that has error code and formats as the given format and args. The parameter `skip` specifies the stack callers skipped amount.
func NewCodef ¶
NewCodef returns an error that has error code and formats as the given format and args.
func NewOption ¶
NewOption creates and returns a custom error with Option. Deprecated: use NewWithOption instead.
func NewSkip ¶
NewSkip creates and returns an error which is formatted from given text. The parameter `skip` specifies the stack callers skipped amount.
func NewSkipf ¶
NewSkipf returns an error that formats as the given format and args. The parameter `skip` specifies the stack callers skipped amount.
func NewWithOption ¶
NewWithOption creates and returns a custom error with Option. It is the senior usage for creating error, which is often used internally in framework.
func Stack ¶
Stack returns the stack callers as string. It returns the error string directly if the `err` does not support stacks.
func Unwrap ¶
Unwrap returns the next level error. It returns nil if current level error or the next level error is nil.
func Wrap ¶
Wrap wraps error with text. It returns nil if given err is nil. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
func WrapCodeSkip ¶
WrapCodeSkip wraps error with code and text. It returns nil if given err is nil. The parameter `skip` specifies the stack callers skipped amount.
func WrapCodeSkipf ¶
WrapCodeSkipf wraps error with code and text that is formatted with given format and args. It returns nil if given err is nil. The parameter `skip` specifies the stack callers skipped amount.
func WrapCodef ¶
WrapCodef wraps error with code and format specifier. It returns nil if given `err` is nil.
func WrapSkip ¶
WrapSkip wraps error with text. It returns nil if given err is nil. The parameter `skip` specifies the stack callers skipped amount. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
func WrapSkipf ¶
WrapSkipf wraps error with text that is formatted with given format and args. It returns nil if given err is nil. The parameter `skip` specifies the stack callers skipped amount. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
Types ¶
type CauseInterface ¶
CauseInterface is the interface for Cause feature.
type CodeInterface ¶
CodeInterface is the interface for Code feature.
type CurrentInterface ¶
CurrentInterface is the interface for Current feature.
type EqualInterface ¶
EqualInterface is the interface for Equal feature.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is custom error for additional features.
func (*Error) Current ¶
Current creates and returns the current level error. It returns nil if current level error is nil.
func (*Error) Equal ¶
Equal reports whether current error `err` equals to error `target`. Please note that, in default comparison for `Error`, the errors are considered the same if both the `code` and `text` of them are the same.
func (*Error) Format ¶
Format formats the frame according to the fmt.Formatter interface.
%v, %s : Print all the error string; %-v, %-s : Print current level error string; %+s : Print full stack error list; %+v : Print the error string and full stack error list
func (*Error) Is ¶
Is reports whether current error `err` has error `target` in its chaining errors. It is just for implements for stdlib errors.Is from Go version 1.17.
func (Error) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.
type IsInterface ¶
IsInterface is the interface for Is feature.
type Option ¶
type Option struct { Error error // Wrapped error if any. Stack bool // Whether recording stack information into error. Text string // Error text, which is created by New* functions. Code codes.Code // Error code if necessary. }
Option is option for creating error.
type StackInterface ¶
StackInterface is the interface for Stack feature.
type UnwrapInterface ¶
UnwrapInterface is the interface for Unwrap feature.