Simple golang package to handle errors with stack info
-
Install
go get -v github.com/bikbah/stackerror
-
Use in error returning code:
package main import ( "errors" "log" "github.com/bikbah/stackerror" ) func main() { if err := f(); err != nil { // prints error with stack log.Fatal(err) } } func f() error { if err := g(); err != nil { return stackerror.New(err) } return nil } func g() error { return errors.New("error in stack depth") }
-
Output
2023/11/01 23:48:16 error in stack depth /dev/go/src/test/stackerror/main.go:18[main.f] /dev/go/src/test/stackerror/main.go:11[main.main] /usr/local/go/src/runtime/proc.go:267[runtime.main] /usr/local/go/src/runtime/asm_arm64.s:1197[runtime.goexit] exit status 1