You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 1, 2021. It is now read-only.
this is an error
main.GiveError
/Users/brianwong/go/src/github.com/brianbwong/test.go:9
main.Outer
/Users/brianwong/go/src/github.com/brianbwong/test.go:13
main.main
/Users/brianwong/go/src/github.com/brianbwong/test.go:18
runtime.main
/usr/local/opt/go/libexec/src/runtime/proc.go:198
runtime.goexit
/usr/local/opt/go/libexec/src/runtime/asm_amd64.s:2361
main.Outer
/Users/brianwong/go/src/github.com/brianbwong/test.go:14
main.main
/Users/brianwong/go/src/github.com/brianbwong/test.go:18
runtime.main
/usr/local/opt/go/libexec/src/runtime/proc.go:198
runtime.goexit
/usr/local/opt/go/libexec/src/runtime/asm_amd64.s:2361
In this toy example, it's obvious that the output of GiveError() already contains a stack trace, so there's no point in Wrapping it. However, if GiveError() is a function in an external package, it won't be clear whether its output contains a stack trace or not (and hence whether it needs wrapping).
If this isn't intended, here's a rough proposal for a fix:
// WithStack annotates err with a stack trace at the point WithStack was called.
// If err is nil, WithStack returns nil.
func WithStack(err error) error {
if err == nil {
return nil
}
_, ok := err.(causer)
if ok {
return err
}
return &withStack{
err,
callers(),
}
}
Though currently it looks like the type fundamental isn't actually a causer.