sperr

package
v0.20.12 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New creates a new sperr.Error with a stack It is recommended that `New` be called from the place where the actual error occurs and not do define errors. This is because sperr.Error is a stateful construct which also encapsulates the stacktrace at the time of creation.

For converting generic errors to sperr.Error the recommended usage pattern is sperr.Wrap or sperr.Wrapf

func ToError

func ToError(val interface{}, options ...Option) error

func Wrap

func Wrap(err error, options ...Option) error

Wrap creates a new sperr.Error if the `error` that is being wrapped is not an sperr.Error

When wrapping an error this also adds a stacktrace into the new `Error` object

func WrapWithMessage

func WrapWithMessage(err error, format string, args ...interface{}) error

func WrapWithRootMessage

func WrapWithRootMessage(err error, format string, args ...interface{}) error

Types

type Error

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

func (*Error) Cause

func (e *Error) Cause() error

Cause returns the underlying cause of this error. Maybe <nil> if this was created with New

func (*Error) Detail

func (e *Error) Detail() string

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

All error values returned from this package implement fmt.Formatter and can be formatted by the fmt package. The following verbs are supported:

		%s    print the error. If the error has a Cause it will be
		      printed recursively.
		%v    see %s
		%+v   detailed format - includes messages and detail.
    %#v   Each Frame of the error's StackTrace will be printed in detail.
	  %q		a double-quoted string safely escaped with Go syntax

TODO: add Details for +

func (*Error) RootCause

func (e *Error) RootCause() error

RootCause will retrieves the underlying root error in the error stack RootCause will recursively retrieve the topmost error that does not have a cause, which is assumed to be the original cause.

func (*Error) Stack

func (e *Error) Stack() StackTrace

Stack retrieves the stack trace of the absolute underlying sperr.Error

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the immediately underlying error

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type Option

type Option func(e *Error) *Error

func WithDetail

func WithDetail(format string, args ...interface{}) Option

func WithMessage

func WithMessage(format string, args ...interface{}) Option

func WithRootMessage

func WithRootMessage(format string, args ...interface{}) Option

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

Jump to

Keyboard shortcuts

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