stack

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 10 Imported by: 2

README

Stack

license

Stack provides stack tracing and enhanced error logging. Much of this code predates pkg/errors supporting marshallable stacktraces but has been updated to have interoperability with it.

Features

  • Grabs full traces at the invocation of the error trace
  • Prevents repeated nesting of traces with automatic merging of new error data
  • Allows for additional data to be attached to errors that can be optionally exported based on the error handling
  • Provides automatic marshalling of entries to Zerolog

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasTrace

func HasTrace(err error) (isStackTraced bool)

HasTrace determines if there is a traceable error

func Trace

func Trace(err error, extra ...ErrorKVP) error

func TraceToString

func TraceToString(err error) string

TraceToString converts a trace to a string that can be read, this doesn't capture the extra data just a stack trace This is mostly used for tests to make it more readable if something melts down

func UpliftStackTrace added in v1.0.2

func UpliftStackTrace(err error) error

func Wrap

func Wrap(err error, message string, extra ...ErrorKVP) error

Types

type Error

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

func GetTrace

func GetTrace(err error) (wrappedErr *Error, useNewError bool)

func ToTypedError added in v1.0.2

func ToTypedError(err error) (typedErr *Error)

func (*Error) Cause

func (es *Error) Cause() error

func (*Error) Extra

func (es *Error) Extra() []ErrorKVP

func (*Error) Format

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

func (*Error) HasStack added in v1.0.2

func (es *Error) HasStack() bool

func (*Error) Is

func (es *Error) Is(target error) bool

func (*Error) MarshalZerologObject

func (es *Error) MarshalZerologObject(e *zerolog.Event)

func (*Error) RawStack added in v1.0.2

func (es *Error) RawStack() MarshableStack

func (*Error) StackTrace

func (es *Error) StackTrace() errors.StackTrace

func (*Error) TopLine

func (es *Error) TopLine() (error, string)

func (*Error) Unwrap

func (es *Error) Unwrap() error

type ErrorKVP

type ErrorKVP struct {
	Key   string
	Value any
}

func (ErrorKVP) MarshalZerologObject

func (e ErrorKVP) MarshalZerologObject(ze *zerolog.Event)

type IStacker

type IStacker interface {
	zerolog.LogObjectMarshaler
	RawStack() MarshableStack
}

type IUnwrapper added in v1.0.2

type IUnwrapper interface {
	Unwrap() error
}

type MarshableStack added in v1.0.2

type MarshableStack []stackFrame

func GetStackProgramCounter

func GetStackProgramCounter(offset int) MarshableStack

func MarshalStack

func MarshalStack() MarshableStack

func (MarshableStack) Format added in v1.0.2

func (m MarshableStack) Format(st fmt.State, verb rune)

func (MarshableStack) MarshalString added in v1.0.2

func (m MarshableStack) MarshalString() string

func (MarshableStack) MarshalStringFrame added in v1.0.2

func (m MarshableStack) MarshalStringFrame(i int) string

func (MarshableStack) MarshalZerologArray added in v1.0.2

func (m MarshableStack) MarshalZerologArray(a *zerolog.Array)

func (MarshableStack) MarshalZerologObject added in v1.0.2

func (m MarshableStack) MarshalZerologObject(e *zerolog.Event)

func (MarshableStack) StackTrace added in v1.0.2

func (m MarshableStack) StackTrace() errors.StackTrace

type PCFrame

type PCFrame uintptr

func (PCFrame) File

func (f PCFrame) File() string

func (PCFrame) Format

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

func (PCFrame) Line

func (f PCFrame) Line() int

func (PCFrame) MarshalJSON

func (f PCFrame) MarshalJSON() ([]byte, error)

func (PCFrame) MarshalZerologObject

func (f PCFrame) MarshalZerologObject(e *zerolog.Event)

func (PCFrame) Name

func (f PCFrame) Name() string

func (PCFrame) PC

func (f PCFrame) PC() uintptr

func (PCFrame) UnmarshalJSON

func (f PCFrame) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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