Documentation
¶
Overview ¶
Package microerror provides project wide helper functions for a more convenient and efficient error handling.
Index ¶
- func Cause(err error) error
- func Desc(err error) string
- func Mask(err error) error
- func Maskf(err error, f string, v ...interface{}) error
- func New(s string) error
- func Newf(f string, v ...interface{}) error
- func Stack(err error) string
- type ErrgoHandler
- type ErrgoHandlerConfig
- type Error
- type Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cause ¶
Cause returns the cause of the given error. If the cause of the err can not be found it returns the err itself.
Cause is the usual way to diagnose errors that may have been wrapped by Mask or Maskf.
func Mask ¶
Mask is a simple error masker. Masked errors act as tracers within the source code. Inspecting an masked error shows where the error was passed through within the code base. This is gold for debugging and bug hunting.
func Maskf ¶
Maskf is like Mask. In addition to that it takes a format string and variadic arguments like fmt.Sprintf. The format string and variadic arguments are used to annotate the given errgo error.
func New ¶
New returns a new error with the given error message. It is a drop-in replacement for errors.New from the standard library.
func Stack ¶
Stack prints the error with the stack if its argument is underlying microerror error or result of Error function otherwise. Its main purpose is to be used for a value for "stack" micrologger key.
Example:
logger.LogCtx(ctx, "level", "error", "message", "failed to do a thing", "stack", microerror.Stack(err))
Types ¶
type ErrgoHandler ¶
type ErrgoHandler struct {
// contains filtered or unexported fields
}
ErrgoHandler implements Handler interface.
func NewErrgoHandler ¶
func NewErrgoHandler(config ErrgoHandlerConfig) *ErrgoHandler
func (*ErrgoHandler) Cause ¶
func (h *ErrgoHandler) Cause(err error) error
func (*ErrgoHandler) Mask ¶
func (h *ErrgoHandler) Mask(err error) error
func (*ErrgoHandler) Maskf ¶
func (h *ErrgoHandler) Maskf(err error, f string, v ...interface{}) error
func (*ErrgoHandler) New ¶
func (h *ErrgoHandler) New(s string) error
func (*ErrgoHandler) Newf ¶
func (h *ErrgoHandler) Newf(f string, v ...interface{}) error
type ErrgoHandlerConfig ¶
type ErrgoHandlerConfig struct {
// CallDepth is useful when creating a wrapper for ErrgoHandler. Its
// value is used to push stack location and skip wrapping function
// location as an origin. The default value is 0.
CallDepth int
}
func DefaultErrgoHandlerConfig ¶
func DefaultErrgoHandlerConfig() ErrgoHandlerConfig
type Error ¶
Error is a predefined error structure whose purpose is to act as container for meta information associated to a specific error. The specific error type matching can be used as usual. The usual error masking and cause gathering can be used as usual. Using Error might look as follows. In the beginning is a usual error defined, along with its matcher. This error is the root cause once emitted during runtime.
var notEnoughWorkersError = µerror.Error{
Desc: "The amount of requested tenant cluster workers exceeds the available number of control plane nodes.",
Docs: "https://github.com/giantswarm/ops-recipes/blob/master/349-not-enough-workers.md",
Kind: "notEnoughWorkersError",
}
func IsNotEnoughWorkers(err error) bool {
return microerror.Cause(err) == notEnoughWorkersError
}
type Handler ¶
type Handler interface {
// New returns a new error with the given error message. It is
// a drop-in replacement for errors.New from the standard library.
//
// NOTE deprecated
//
New(s string) error
// Newf returns a new error with the given printf-formatted error
// message.
//
// NOTE deprecated
//
Newf(f string, v ...interface{}) error
// Cause returns the cause of the given error. If the cause of the err can not
// be found it returns the err itself.
//
// Cause is the usual way to diagnose errors that may have been wrapped by Mask
// or Maskf.
Cause(err error) error
// Mask is a simple error masker. Masked errors act as tracers within the
// source code. Inspecting an masked error shows where the error was passed
// through within the code base. This is gold for debugging and bug hunting.
Mask(err error) error
// Maskf is like Mask. In addition to that it takes a format string and
// variadic arguments like fmt.Sprintf. The format string and variadic
// arguments are used to annotate the given error.
Maskf(err error, f string, v ...interface{}) error
}