merr

package
v2.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package merr extends the errors package with features like key-value attributes for errors, embedded stacktraces, and multi-errors.

merr functions takes in generic errors of the built-in type. The returned errors are wrapped by a type internal to merr, and appear to also be of the generic error type.

As is generally recommended for go projects, errors.Is and errors.As should be used for equality checking.

Index

Constants

This section is empty.

Variables

View Source
var MaxStackSize = 50

MaxStackSize indicates the maximum number of stack frames which will be stored when embedding stack traces in errors.

Functions

func New

func New(ctx context.Context, str string) error

New is a shortcut for:

merr.WrapSkip(ctx, errors.New(str), 1)

func Wrap

func Wrap(ctx context.Context, err error) error

Wrap returns a copy of the given error wrapped in an Error. If the given error is already wrapped in an *Error then the given context is merged into that one with mctx.MergeAnnotations instead.

Wrapping nil returns nil.

func WrapSkip

func WrapSkip(ctx context.Context, err error, skip int) error

WrapSkip is like Wrap but also allows for skipping extra stack frames when embedding the stack into the error.

Types

type Error

type Error struct {
	Err        error
	Ctx        context.Context
	Stacktrace Stacktrace
}

Error wraps an error such that contextual and stacktrace information is captured alongside that error.

func (Error) Error

func (e Error) Error() string

Error implements the method for the error interface.

func (Error) FullError

func (e Error) FullError() string

FullError returns an error string which includes contextual annotations and stacktrace information.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap implements the method for the errors package.

type Stacktrace

type Stacktrace struct {
	// contains filtered or unexported fields
}

Stacktrace represents a stack trace at a particular point in execution.

func (Stacktrace) Frame

func (s Stacktrace) Frame() runtime.Frame

Frame returns the first frame in the stack.

func (Stacktrace) Frames

func (s Stacktrace) Frames() []runtime.Frame

Frames returns all runtime.Frame instances for this stack.

func (Stacktrace) FullString

func (s Stacktrace) FullString() string

FullString returns the full stack trace.

func (Stacktrace) String

func (s Stacktrace) String() string

String returns a string representing the top-most frame of the stack.

Jump to

Keyboard shortcuts

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