errorutil

package
v0.0.0-...-4e18fe8 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package errorutil provides utilities to handle errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithStack

func WithStack(err error) error

WithStack wraps the passed error into a StackError and attaches the stack trace of the caller to it.

Types

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame.

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
%+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 StackError

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

StackError is a wrapper error that provides a stacktrace for the error.

func (*StackError) Error

func (e *StackError) Error() string

func (*StackError) StackTrace

func (e *StackError) StackTrace() StackTrace

func (*StackError) Unwrap

func (e *StackError) Unwrap() error

type StackTrace

type StackTrace []Frame

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

func GenerateStackTrace

func GenerateStackTrace(skip int) StackTrace

GenerateStackTrace generates a StackTrace. It skips the given amount of callers.

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.

func (StackTrace) String

func (st StackTrace) String() string

Jump to

Keyboard shortcuts

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