Skip to content
Same as fmt.Errorf but with stack trace.
Go Makefile
Branch: master
Clone or download
Latest commit e3c770b Nov 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Base implementation Nov 10, 2019
.travis.yml
LICENSE Base implementation Nov 10, 2019
Makefile Base implementation Nov 10, 2019
README.md Base implementation Nov 10, 2019
bench_test.go Base implementation Nov 10, 2019
error.go Base implementation Nov 10, 2019
example_test.go Base implementation Nov 10, 2019
go.mod Base implementation Nov 10, 2019
go.sum Base implementation Nov 10, 2019
helper_test.go Base implementation Nov 10, 2019
stack.go Base implementation Nov 10, 2019
stack_test.go Base implementation Nov 10, 2019

README.md

Annotation with stack trace for go1.13

GoDoc Report Build Status

Go 1.13 contains support for error wrapping. Now you can add additional information to an error by wrapping it using the new %w verb at fmt.Errorf and examine such errors using errors.Is and errors.As. If you also want to save a stack trace of an error instead of fmt.Errorf use stack.Errorf which is compatible with errors.Is and errors.As and also gives the ability to get a stack trace of the error using stack.Trace function which will return []runtime.Frame.

  • Import.
import "github.com/romanyx/stack
  • Annotate error.
func example() error {
	if err := call(); err != nil {
		return stack.Errorf("call: %w", err)
	}

	return nil
}
  • Print original error.
stack.Origin(err)
  • Iterate through stack trace.
for _, frame := range stack.Trace(err) {
	fmt.Printf("%s:%d %s()\n", frame.File, frame.Line, frame.Function)
}
You can’t perform that action at this time.