errors

package
v0.110.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

OpenMFP Errors

The errors package is a drop-in replacement for the stdlib errors package but enhances all errors with a stacktrace. This is especially useful in combination with Sentry as it implements the StackFrames() function that the Sentry SDK uses to collect data to show a call history.

Usage

This package can be used like the default stdlib errors package. Just switch the import from errors to github.com/openmfp/golang-commons/errors.

Instead of fmt.Errorf() to wrap errors you can use the errors.Errorf() function from this package or the helper functions errors.Wrap() or errors.Wrapf(). All of the above return an error with attached stack trace.

To add the current stacktrace to an existing error use the errors.WithStack() util function.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	As        = errors.As
	Is        = errors.Is
	Cause     = errors.Cause
	Unwrap    = errors.Unwrap
	WithStack = errors.WithStack
)

Export a number of functions or variables from pkg/errors. We want people to be able to use them, if only via the entrypoints we've vetted in this file.

Functions

func EnsureStack

func EnsureStack(cause error) error

EnsureStack checks if error has a stack, if not adds stack information, otherwise leaves the error unmodified. This can be used to forward an error without adding to the stack, but also adding a stack in case this information is missing.

func New

func New(msg string, args ...interface{}) error

New acts as pkg/errors.New does, producing a stack traced error, but supports interpolating of message parameters. Use this when you want the stack trace to start at the place you create the error.

func PopStack

func PopStack(err error) error

PopStack removes the top of the stack from an errors stack trace.

func Sentinel

func Sentinel(msg string, args ...interface{}) error

Sentinel is used to create compile-time errors that are intended to be value only, with no associated stack trace.

func Wrap

func Wrap(cause error, msg string, args ...interface{}) error

Wrap creates a new error from a cause, decorating the original error message with a prefix.

It differs from the pkg/errors Wrap/Wrapf by idempotently creating a stack trace, meaning we won't create another stack trace when there is already a stack trace present that matches our current program position.

Types

type OperatorError

type OperatorError interface {
	Err() error
	Retry() bool
	Sentry() bool
}

func NewOperatorError

func NewOperatorError(err error, retry bool, sentry bool) OperatorError

type StackTrace

type StackTrace = errors.StackTrace

StackTrace should be aliases rather than newtype'd, so it can work with any of the functions we export from pkg/errors.

type StackTracer

type StackTracer interface {
	StackTrace() errors.StackTrace
}

Jump to

Keyboard shortcuts

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