emicklei / tre

Go package for tracing an error in the call stack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tre - tracing error in the call stack

Package tre has the TracingError type to collect stack information when an error is caught.

GoDoc Go Report Card codecov

usage

package main

import (
	"errors"
	"fmt"

	"github.com/emicklei/tre"
)

func main() {
	err := doThis("sing")
	fmt.Println(err.Error())
}

func doThis(task string) error {
	err := doMore("prepare")
	return tre.New(err, "failed to do this", "task", task)
}

func doMore(task string) error {
	ctx := map[string]any{"task": task, "guality": 42}
	return tre.New(doThat(task), "cannot do more", ctx)
}

func doThat(task string) error {
	return tre.New(errors.New("bummer"), "doing that failed", "task", task)
}

see examples/main.go

(c) 2016, http://ernestmicklei.com. MIT License

About

Go package for tracing an error in the call stack

License:MIT License


Languages

Language:Go 100.0%