Documentation ¶
Overview ¶
Package zerrors is a wrapper around golang.org/x/xerrors with some additional features.
Index ¶
- Constants
- Variables
- func As(err error, target interface{}) bool
- func Errorf(format string, a ...interface{}) error
- func FormatError(f Formatter, s fmt.State, verb rune)
- func Is(err error, target error) bool
- func IsType(err TypeAwareError, errType fmt.Stringer) bool
- func Mask(err error) error
- func New(msg string) error
- func NewWithOpts(msg string, opts ...ErrorOpt) error
- func Newf(format string, a ...interface{}) error
- func Opaque(err error) error
- func Unwrap(err error) error
- func WalkErrChain(err error, f func(err error) interface{}) interface{}
- func Wrap(err error, msg string) error
- func WrapPtr(errp *error, msg string)
- func WrapPtrWithOpts(errp *error, msg string, opts ...ErrorOpt)
- func WrapPtrf(errp *error, format string, args ...interface{})
- func WrapWithOpts(err error, msg string, opts ...ErrorOpt) error
- func Wrapf(err error, format string, args ...interface{}) error
- type ContextAwareError
- type ErrorOpt
- type ErrorType
- type Formatter
- type Frame
- type Printer
- type TypeAwareError
- type Wrapper
Constants ¶
const GenericError = ErrorType("GenericError")
GenericError is the default error type.
Variables ¶
var DefaultSkipCallers = 0 //nolint:gochecknoglobals
DefaultSkipCallers exposes the default value that should be used for caller frame skipping This can be adjusted within an init function.
Functions ¶
func Errorf ¶
Errorf see: https://pkg.go.dev/golang.org/x/xerrors#Errorf
func FormatError ¶
FormatError see: https://pkg.go.dev/golang.org/x/xerrors#FormatError
func IsType ¶
func IsType(err TypeAwareError, errType fmt.Stringer) bool
IsType Check if a given error is matching given type Example:
zerrors.IsType(err, MyErrorTypeWithStringerInterface)
func NewWithOpts ¶
NewWithOpts creates a new error with optional passed options see: ./options.go for available options
func Opaque ¶
Opaque see: https://pkg.go.dev/golang.org/x/xerrors#Opaque
func Unwrap ¶
Unwrap see: https://pkg.go.dev/golang.org/x/xerrors#Unwrap
func WalkErrChain ¶
WalkErrChain provides a simple way to walk e error chain using Unwrap function.
func WrapPtr ¶
WrapPtr wraps a given error pointer with a new zError instance This is useful for defer used with named return types.
func WrapPtrWithOpts ¶
WrapPtrWithOpts wraps an error pointer.
func WrapPtrf ¶
WrapPtrf wraps a given error pointer with a new zError instance and allows format message string This is useful for defer used with named return types.
func WrapWithOpts ¶
WrapWithOpts wraps an error.
Types ¶
type ContextAwareError ¶
type ContextAwareError interface { // implement error interface here error // Context does a recursive lookup for context.Context and returns the first contexts in err´s chain Context() context.Context // ContextValue does a recursive lookup for a context value for given key. It returns nil if no value can be found. ContextValue(key interface{}) interface{} }
ContextAwareError defines an error that contains an context.
type ErrorOpt ¶
type ErrorOpt func(e *zError)
ErrorOpt defines the option function.
func WithContext ¶
WithContext allows passing a context to the error.
func WithContextValue ¶
func WithContextValue(key interface{}, value interface{}) ErrorOpt
WithContextValue allows passing a key/value pair to the error, which is stored inside the context.Context NOTE: If no context is defined while this option is applied, it will create an empty context using context.TODO().
func WithSkipCallers ¶
WithSkipCallers allows defining how many caller frames should be skipped. This only applies to output format `%+v` that prints the stacktrace.
func WithWrappedError ¶
WithWrappedError allows to pass an error that should be wrapped.
type ErrorType ¶
type ErrorType string
ErrorType defines an easy to use fmt.Stringer compatible error type. Example:
zerrors.ErrorType("MyNamedErrorType")
type Formatter ¶
Formatter see: https://pkg.go.dev/golang.org/x/xerrors#Formatter
type Frame ¶
Frame see: https://pkg.go.dev/golang.org/x/xerrors#Frame
func Caller ¶
Caller see: https://pkg.go.dev/golang.org/x/xerrors#Caller
type Printer ¶
Printer see: https://pkg.go.dev/golang.org/x/xerrors#Printer
type TypeAwareError ¶
type TypeAwareError interface { // implement error interface here error // Type returns the ErrorType Type() fmt.Stringer // IsType checks if error is of passed ErrorType IsType(errType fmt.Stringer) bool }
TypeAwareError defines an error that is aware of its type.
type Wrapper ¶
Wrapper see: https://pkg.go.dev/golang.org/x/xerrors#Wrapper