Documentation
¶
Overview ¶
Package oops implements the batteries that are missing from the errors package.
Index ¶
- func CaptureRuntimeFrames(_ error, skip int) []runtime.Frame
- func Chain(errs ...error) error
- func ChainP(err *error, errs ...error)
- func ErrorMarshalJSON(e error) (bs []byte, err error)
- func New(format string, a ...any) error
- func SetDefaultCapturer(c Capturer)
- func ShadowF(hidden *error, err error) func()
- func ShadowP(hidden *error, err error)
- type CaptureFunc
- type Capturer
- type ChainError
- type Frames
- type Namespace
- type NamespaceError
- type ShadowError
- type TraceError
- type TraceOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureRuntimeFrames ¶ added in v0.0.2
CaptureRuntimeFrames returns the captured stack as []runtime.Frame.
func ErrorMarshalJSON ¶
ErrorMarshalJSON uses e's json.Marshaler if it implements one otherwise it uses the output from e.Error() (marshalled into a JSON string).
func New ¶
New returns a new error from fmt.Errorf with a stack trace.
Example ¶
package main import ( "fmt" "github.com/calebcase/oops" ) func main() { a := func() error { return oops.New("bad stuff") } b := func() error { return a() } c := func() error { return b() } err := c() fmt.Printf("error: %v\n", err) }
Output: error: bad stuff
Example (Details) ¶
package main import ( "fmt" "github.com/calebcase/oops" ) func main() { a := func() error { return oops.New("bad stuff") } b := func() error { return a() } c := func() error { return b() } err := c() fmt.Printf("error: %+v\n", err) }
func SetDefaultCapturer ¶ added in v0.0.2
func SetDefaultCapturer(c Capturer)
SetDefaultCapturer changes the default trace capturer used by calls to Trace, TraceN, and TraceWithOptions. The default capturer creates a capture using CaptureFrames.
Types ¶
type CaptureFunc ¶ added in v0.0.2
CaptureFunc defines a Capturer that calls the given function to generate the capture.
type ChainError ¶
type ChainError []error
ChainError is a list of errors oldest to newest.
func (ChainError) As ¶ added in v0.0.6
func (ce ChainError) As(target any) bool
As implements the implied interface for errors.As.
func (ChainError) Error ¶
func (ce ChainError) Error() string
Error implements the implied interface for error.
func (ChainError) Format ¶
func (ce ChainError) Format(f fmt.State, verb rune)
Format implements fmt.Format.
func (ChainError) Is ¶ added in v0.0.6
func (ce ChainError) Is(err error) bool
Is implements the implied interface for errors.Is.
func (ChainError) Unwrap ¶
func (ce ChainError) Unwrap() error
Unwrap implements the implied interface for errors.Unwrap.
type Frames ¶ added in v0.0.2
Frames wraps []runtime.Frame to provide a custom stringer.
func CaptureFrames ¶ added in v0.0.2
CaptureFrames returns the captured stack as Frames.
type Namespace ¶
type Namespace string
Namespace provides a name prefix for new errors.
func (Namespace) New ¶
func (n Namespace) New(err error) *NamespaceError
New returns the error wrapped in the namespace.
type NamespaceError ¶
NamespaceError prefixes errors with the given namespace.
func (*NamespaceError) Error ¶
func (ne *NamespaceError) Error() string
func (*NamespaceError) Format ¶
func (ne *NamespaceError) Format(f fmt.State, verb rune)
Format implements fmt.Format.
func (*NamespaceError) MarshalJSON ¶
func (ne *NamespaceError) MarshalJSON() (bs []byte, err error)
MarshalJSON implements json.Marshaler.
func (*NamespaceError) Unwrap ¶
func (ne *NamespaceError) Unwrap() error
type ShadowError ¶
ShadowError is an error with a hidden error inside.
func Shadow ¶
func Shadow(hidden, err error) *ShadowError
Shadow hides internal errors with another error.
func (*ShadowError) Error ¶
func (se *ShadowError) Error() string
func (*ShadowError) Format ¶
func (se *ShadowError) Format(f fmt.State, verb rune)
Format implements fmt.Format.
func (*ShadowError) MarshalJSON ¶
func (se *ShadowError) MarshalJSON() (bs []byte, err error)
MarshalJSON implements json.Marshaler.
func (*ShadowError) Unwrap ¶
func (se *ShadowError) Unwrap() error
type TraceError ¶
TraceError is an error with trace data.
func Trace ¶
func Trace(err error) *TraceError
Trace captures a trace and combines it with err. Tracer is use to capture the trace data and 2 levels are skipped.
func TraceN ¶
func TraceN(err error, skip int) *TraceError
TraceN captures a trace and combines it with err. Capturer is use to capture the trace data with skipped levels.
func TraceWithOptions ¶
func TraceWithOptions(err error, options TraceOptions) *TraceError
TraceWithOptions captures a trace using the given options.
func (*TraceError) Format ¶
func (te *TraceError) Format(f fmt.State, verb rune)
Format implements fmt.Format.
func (*TraceError) MarshalJSON ¶
func (te *TraceError) MarshalJSON() (bs []byte, err error)
MarshalJSON implements json.Marshaler.
func (*TraceError) Unwrap ¶
func (te *TraceError) Unwrap() error
Unwrap implements the implied interface for errors.Unwrap.
type TraceOptions ¶
type TraceOptions struct { // Skip the given number of levels of tracing. Default is 0. Skip int // Capturer controls the specific capturer implementation to use. If // not set, then the package level Capture will be used. Capturer Capturer }
TraceOptions allows setting specific options for the trace.