Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MaxStackDepth = 50
MaxStackDepth the maximum number of frames collected when creating a new Error.
Functions ¶
func Errorf ¶
Errorf is a shortcut for `errors.New(fmt.Errorf("format", args))`. Be careful when using this, this will result in losing the callers of the original error if one of the `args` is of type `*errors.Error`.
func New ¶
New create a new `*Error`. Collects the function callers.
If the given reason is already of type `*Error`, returns it without change. If the reason is a slice of `error`, joins them using std's `errors.Join`.
If the given reason is `nil`, returns `nil`. If the reason is `[]error` or `[]any`, the `nil` elements are ignored.
If the reason is anything other than an `error`, `[]error`, `*Error`, `[]*Error`, `[]any`, it will be wrapped in a `Reason` structure, allowing to preserve its JSON marshaling behavior.
func NewSkip ¶
NewSkip create a new `*Error`. Collects the function callers, skipping the given amount of frames.
If the given reason is already of type `*Error`, returns it without change. If the reason is a slice of `error`, joins them using std's `errors.Join`.
If the given reason is `nil`, returns `nil`. If the reason is `[]error` or `[]any`, the `nil` elements are ignored.
If the reason is anything other than an `error`, `[]error`, `*Error`, `[]*Error`, `[]any`, it will be wrapped in a `Reason` structure, allowing to preserve its JSON marshaling behavior.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps an errors and attaches callers at the time of creation. This implementation provides information for debugging or error reporting. It is encouraged to use this type of error everywhere a function can return an unexpected error. Functions returning an error that is only indicative should not use this error type (e.g.: user errors).
func (Error) Callers ¶
Callers returns the function callers collected at the time of creation of the `Error`.
func (Error) MarshalJSON ¶
MarshalJSON marshals the error and its underlying reasons. The result will be: - a string if the reasons slice is empty - the marshaled first reason if the reasons slice contains only one error - an array of the marshaled reasons otherwise
func (Error) StackFrames ¶
func (e Error) StackFrames() FrameStack
StackFrames returns the parsed `FrameStack` for this error.
type FrameStack ¶
FrameStack slice of frames containing information about the stack. Can be used to generate a stack trace for debugging, or for error reporting.
func (FrameStack) String ¶
func (s FrameStack) String() string
type Reason ¶
type Reason struct {
// contains filtered or unexported fields
}
Reason wrapper around any type of error Reason. This allows json marshaling of the Reason instead of losing the original data using `%v` format. Calling `Error()` on this structure returns the original data formatted with `%v`.
func (Reason) MarshalJSON ¶
MarshalJSON marshals the wrapped reason.