trace

package module
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 4 Imported by: 14

README

go-stacktrace

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Max callstack depth to return
	PcSize = 10

	// 1 for trace(), 1 for err.Trace()
	CallersToSkip = 2
)

Functions

func Json added in v0.1.11

func Json(unknown error) string

Attempts to marshal an error, returns default error string if not

func String

func String(unknown error) string

Calls `String()` if implemented by the given error, otherwise calls `Error()`

Types

type Error

type Error struct {
	Name    string                 `json:"name"`
	Message string                 `json:"message"`
	Meta    map[string]interface{} `json:"meta"`
	Stack   []Frame                `json:"stack"`
}

Struct representing an error.

func Guarantee

func Guarantee(unknown error) *Error

Create a new instance of `Error` from an error

If `unknown` is of type `Error`, it returns a clone

func New added in v0.1.3

func New(name string) *Error

Create a new instance of `Error` with a name.

func (*Error) Add

func (e *Error) Add(key string, value interface{}) *Error

Attaches a named value to the metadata of the error.

Note: values will eventually get casted into string with `fmt.Sprintf("%+v", value)`.

func (*Error) Clone

func (e *Error) Clone() *Error

Creates a new instance of the Error without a stack trace.

func (*Error) DeepClone added in v0.1.6

func (e *Error) DeepClone() *Error

Creates a deep-copied clone of the Error including stack trace.

func (*Error) Error

func (e *Error) Error() string

Returns superficial information about the error (name and message).

Required to satisfy the error interface.

func (*Error) GetMeta

func (e *Error) GetMeta() []string

Returns any metadata attached to the error

func (*Error) GetStack

func (e *Error) GetStack() []string

Returns the current status of the stacktrace

func (*Error) String

func (e *Error) String() string

Returns everything about the error (name, message, stacktrace, meta)

func (*Error) Trace

func (e *Error) Trace(err error) *Error

Takes on the message of the given message and traces the callstack.

Note: should be called when returning an error.

Note: will ignore subsequent calls to `Error.Trace` once a stacktrace exists, call `Error.Clone` to create a fresh instance to guarantee a new trace.

func (*Error) Tracef added in v0.1.2

func (e *Error) Tracef(message string, a ...interface{}) *Error

Convenience function that wraps `fmt.Errorf`, otherwise behaves the same as `Error.Trace`.

Should be called when returning an error

type Frame added in v0.1.1

type Frame struct {
	Function string `json:"function"`
	Line     int    `json:"line"`
	File     string `json:"file"`
}

Struct containing information about a stackframe

type SerializableError added in v0.1.4

type SerializableError interface {
	GetStack() []string
	GetMeta() []string
	String() string
	Error() string
}

type TraceableError added in v0.1.4

type TraceableError interface {
	Add(key string, value interface{}) *Error
	Trace(err error) *Error
	Tracef(message string, a ...interface{}) *Error
	Clone() *Error
	DeepClone() *Error
}

Jump to

Keyboard shortcuts

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