Documentation ¶
Index ¶
- Variables
- func Append(err1, err2 error) error
- func MarshalErrkitErrorToJSON(err *errkitError) ([]byte, error)
- func New(message string, details ...any) error
- func WithCause(err, cause error, details ...any) error
- func WithStack(err error, details ...any) error
- func Wrap(err error, message string, details ...any) error
- type ErrorDetails
- type ErrorList
Constants ¶
This section is empty.
Variables ¶
var ( Is = errors.Is As = errors.As Unwrap = errors.Unwrap NewSentinelErr = errors.New )
Make an aliases for errors.Is, errors.As, errors.Unwrap To avoid additional imports
Functions ¶
func Append ¶
Append creates a new combined error from err1, err2. If either error is nil, then the other error is returned.
func WithCause ¶
WithCause adds a cause to the given pure error. It returns nil when passed error is nil.
Intended for use when a function wants to return a well known error, but at the same time wants to add a reason E.g.:
var ErrNotFound = errkit.NewSentinelErr("Resource not found") ...
func SomeFunc() error { ... err := DoSomething() if err != nil { return errkit.WithCause(ErrNotFound, err) } ... }
func WithStack ¶
WithStack wraps the given error with a struct that when serialized to JSON will return a JSON object with the error message and error stack data.
Returns nil when nil is passed.
var ErrWellKnownError = errors.New("Well-known error") ... if someCondition { return errkit.WithStack(ErrWellKnownError) }
Types ¶
type ErrorDetails ¶
func ToErrorDetails ¶
func ToErrorDetails(details []any) ErrorDetails
ToErrorDetails accepts either an even size array which contains pais of key/value or array of one element of ErrorDetails type. Result of function is an ErrorDetails