Documentation ¶
Overview ¶
Package tre has the TracingError type to collect stack information when an error is caught.
It is inspired the minio probe package ; this one is leaner and has no external dependencies.
func main() { err := doSomething("demo") println(tre.New(err, "doSomething failed").Error()) } func doSomething(with string) error { err := doAnotherThingThatCanFail(with) return tre.New(err, "doAnotherThingThatCanFail failed", "with", with) // pass error, message and context } func doAnotherThingThatCanFail(with string) error { return errors.New("something bad happened") }
The TracingError Error() function returns a verbose output of stack information including file,line,function,message and custom key,values.
main.go:11 main.main:doSomething failed main.go:16 main.doSomething:doAnotherThingThatCanFail failed with=demo something bad happened
(c) 2016, http://ernestmicklei.com. MIT License
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a TracingError with a failure message and optional context information. It accepts either an error, a TracingError or nil. If the error is nil then return nil. Context information can either be provided as keys and values (e.g. "key1", value1, "key2", value2, etc) or can be provided as a map[string]interface{} context object.
Types ¶
type CompositeError ¶ added in v1.4.0
type CompositeError struct {
// contains filtered or unexported fields
}
CompositeError holds errors
func NewErrors ¶ added in v1.4.0
func NewErrors() *CompositeError
NewErrors returns a new CompositeError to collect errors and build a single error.
func (*CompositeError) Add ¶ added in v1.4.0
func (c *CompositeError) Add(err error) *CompositeError
Adds a an error to the list unless it is nil.
func (*CompositeError) Err ¶ added in v1.4.0
func (c *CompositeError) Err() error
Err creates a new error with a message composed of each error
func (*CompositeError) Errorf ¶ added in v1.4.0
func (c *CompositeError) Errorf(msg string, args ...any) *CompositeError
Errorf add a new error.
type TracingError ¶
type TracingError struct {
// contains filtered or unexported fields
}
TracingError encapsulates an error and collects tracing information back to the point where it is handled (logged,ignored,responded...).
func (TracingError) As ¶ added in v1.2.0
func (e TracingError) As(target interface{}) bool
As assists with errors.Unwrap
func (TracingError) Error ¶
func (e TracingError) Error() string
Error returns a pretty report of this error.
func (TracingError) LoggingContext ¶
func (e TracingError) LoggingContext() map[string]interface{}
LoggingContext collects all data for context aware logging purposes. Fixed keys are {err,err.type,msg,stack} unless the value is empty.
func (TracingError) Unwrap ¶ added in v1.2.0
func (e TracingError) Unwrap() error
Unwrap to be able to easily nest/unnest