herr

package
v0.27.3 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("value is invalid")

ErrInvalid indicates that a value or operation is invalid.

Functions and methods should not return this error but should instead return a wrap of this one.

View Source
var ErrUnexpected = errors.New("unexpected error")

ErrUnexpected indicates that the error is unexpected but happened. It's useful for debugging.

Functions and methods should not return this error but should instead return a wrap of this one.

Functions

func Format added in v0.27.1

func Format(format string, args ...any) error

Format create error with format and args.

func New

func New(message string) error

New create error with message.

func Unwrap added in v0.26.1

func Unwrap(err error) error

Unwrap try to unwrap the err in *TracedError.

func With

func With(err error, message string) error

With wrap err as TracedError with message.

With doesn't reuse underlying TracedError if exists.

func Wrap

func Wrap(err error, message string) error

Wrap construct stack TracedError by err and message.

Wrap try to use existing stack. If the err is already a [TracedError], it appends the message to the existing one.

func Wrapf

func Wrapf(err error, format string, args ...any) error

Wrapf wraps an error into a TracedError, appending a formatted message.

Wrapf try to use existing stack. If the err is already a [TracedError], it appends the message to the existing one.

Types

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 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.

type TracedError

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

func (*TracedError) Error

func (w *TracedError) Error() string

func (*TracedError) Format

func (w *TracedError) Format(s fmt.State, verb rune)

func (*TracedError) Message

func (w *TracedError) Message() string

func (*TracedError) SetUnderlying

func (w *TracedError) SetUnderlying(err error)

SetUnderlying replace the underlying to new one.

func (*TracedError) Stack

func (w *TracedError) Stack() StackTrace

func (TracedError) StackTrace

func (s TracedError) StackTrace() StackTrace

func (*TracedError) Unwrap

func (w *TracedError) Unwrap() error

Unwrap provides compatibility for Go 1.13 error chains.

Jump to

Keyboard shortcuts

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