errors

package
v0.0.0-...-d71eb57 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 5 Imported by: 0

README

Error Constructor

Error constructor function for helping create custom errors.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxStackDepth = 32

The maximum number of stackframes on any error.

Functions

func WithStack

func WithStack(err error, skip int) error

WithStack annotates err with a skipable stack trace. If err is nil, WithStack returns nil.

It's useful when you want to create a custom error type or custom error constructor function.

skip parameter indicates how many stack frames to skip when recording the stack trace. skip = 0 means that the stack trace should begin at your current function call. skip = 1 means that the stack trace should begin at the caller of your function.

func Wrap

func Wrap(err error, skip int, message string) error

Wrap returns an error annotating err with a skipable stack trace and the supplied message.

It's useful when you want to create a custom error type or custom error constructor function.

skip parameter indicates how many stack frames to skip when recording the stack trace. skip = 0 means that the stack trace should begin at your current function call. skip = 1 means that the stack trace should begin at the caller of your function.

func Wrapf

func Wrapf(err error, skip int, format string, args ...interface{}) error

Wrapf returns an error annotating err with a skipable stack trace and the format specifier.

It's useful when you want to create a custom error type or custom error constructor function.

skip parameter indicates how many stack frames to skip when recording the stack trace. skip = 0 means that the stack trace should begin at your current function call. skip = 1 means that the stack trace should begin at the caller of your function.

Types

type StackFrame

type StackFrame uintptr

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

func (StackFrame) Format

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

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

%s	function name and source file
%v	function name, source file and line number

Format accepts flag "+" for %s and %v verbs for printing source file with relative path to the compile time.

func (StackFrame) Info

func (f StackFrame) Info() (name string, file string, line int)

Info returns the name, file and line number for this Frame's pc.

name is the name of the function, or "unknown". file is the full path to the file that contains the function, or "unknown". line is the line number of the source code of the function.

func (StackFrame) MarshalText

func (f StackFrame) 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 Stacks

type Stacks []uintptr

Stacks represents a Stacks of program counters.

func Callers

func Callers(skip int) *Stacks

Callers returns stack of program counters.

func (*Stacks) Format

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

Jump to

Keyboard shortcuts

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