errs

package
v0.4.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause first checks for `Unwrap` returning the result if available, otherwise returns the result of `Cause`. If neither are available returns nil.

This supports both Go 1.13+ style `UnWrap` and pkg.errors style `Cause` chaining.

func MarshalStack

func MarshalStack(err error) interface{}

MarshalStack is a helper to extract the stack trace from an error and make it available as an easily marshalled object (array of file/line/func).

func RootCause

func RootCause(err error) error

RootCause follows the error chain until Cause() and UnWrap() are not available or return nil.

func WithStack

func WithStack(e interface{}, skip int) error

WithStack wraps the `e` and records the stack, skipping `skip` frames in the stack. 0 skip is considered the function that calls WithStack.

Types

type Frame

type Frame struct {
	File string
	Line int
	Func string
}

Frame is a simple view of the call stack frame.

func ExtractStackFrame

func ExtractStackFrame(err error) []Frame

ExtractStackFrame extracts an embedded array of stack pointers and converts to array of Frames.

func ExtractStackFrameStop

func ExtractStackFrameStop(err error, stopFuncName string) []Frame

ExtractStackFrameStop works the same as ExtractStackFrame, but allows defining a stop function for the stack. Useful for filtering out stack elements that are mostly redundant and simplifying logging and review.

func (Frame) String

func (f Frame) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL