probe

package
v0.0.0-...-2ed4cd9 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 8 Imported by: 24

Documentation

Overview

Package probe implements a simple mechanism to trace and return errors in large programs.

Package probe implements a simple mechanism to trace and return errors in large programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSysInfo

func GetSysInfo() map[string]string

GetSysInfo returns useful system statistics.

func Init

func Init()

Init initializes probe. It is typically called once from the main() function or at least from any source file placed at the top level source directory.

func SetAppInfo

func SetAppInfo(key, value string)

SetAppInfo sets app speific key:value to report additionally during call trace dump. Eg. SetAppInfo("ReleaseTag", "RELEASE_42_0")

SetAppInfo("Version", "42.0")
SetAppInfo("Commit", "00611fb")

func WrapError

func WrapError(err *Error) error

WrapError function wraps a *probe.Error into a 'error' compatible duck type.

Types

type Error

type Error struct {
	Cause     error             `json:"cause,omitempty"`
	CallTrace []TracePoint      `json:"trace,omitempty"`
	SysInfo   map[string]string `json:"sysinfo,omitempty"`
	// contains filtered or unexported fields
}

Error implements tracing error functionality.

func NewError

func NewError(e error) *Error

NewError function instantiates an error probe for tracing. Default “error“ (golang's error interface) is injected in only once. Rest of the time, you trace the return path with “probe.Trace“ and finally handling them at top level

Following dummy code talks about how one can pass up the errors and put them in CallTrace.

func sendError() *probe.Error {
     return probe.NewError(errors.New("Help Needed"))
}
func recvError() *probe.Error {
     return sendError().Trace()
}
if err := recvError(); err != nil {
      log.Fatalln(err.Trace())
}

func UnwrapError

func UnwrapError(err error) (*Error, bool)

UnwrapError tries to convert generic 'error' into typed *probe.Error and returns true, false otherwise.

func (*Error) String

func (e *Error) String() string

String returns error message.

func (*Error) ToGoError

func (e *Error) ToGoError() error

ToGoError returns original error message.

func (*Error) Trace

func (e *Error) Trace(fields ...string) *Error

Trace records the point at which it is invoked. Stack traces are important for debugging purposes.

func (*Error) Untrace

func (e *Error) Untrace() *Error

Untrace erases last known trace entry.

type TracePoint

type TracePoint struct {
	Line     int                 `json:"line,omitempty"`
	Filename string              `json:"file,omitempty"`
	Function string              `json:"func,omitempty"`
	Env      map[string][]string `json:"env,omitempty"`
}

TracePoint container for individual trace entries in overall call trace

Jump to

Keyboard shortcuts

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