pkg / errors

Simple error handling primitives
https://godoc.org/github.com/pkg/errors
BSD 2-Clause "Simplified" License
8.19k stars 695 forks source link

Ignore Callstack above printing location #111

Open e-nikolov opened 7 years ago

e-nikolov commented 7 years ago

Is it possible when printing an error to only print the Callstack that is generated from this position onward, but ignore the Callstack that happened prior to the method that prints the error?

For instance if I am using a webserver, such as negroni, it includes a lot of function calls which happen before reaching my code. These calls are still included in the stack trace, and clutter it, but I am not particularly interested in them.

Is there a way to ignore them?

If there isn't at present, maybe something can be done to match the runtime.Callers at the printing location with the stack trace inside the error, and ignore the matching part?

davecheney commented 7 years ago

In a word yes, but also no.

errors from this package support a StackTrace() []Frame interface which you can use to get the various pcs of the stack trace. You can filter it yourself

https://godoc.org/github.com/pkg/errors#example-package--StackTrace

On Sun, Mar 26, 2017 at 3:59 AM, e-nikolov notifications@github.com wrote:

Is it possible when printing an error to only print the Callstack that is generated from this position onward, but ignore the Callstack that happened prior to the method that prints the error?

For instance if I am using a webserver, such as negroni, it includes a lot of function calls which happen before reaching my code. These calls are still included in the stack trace, and clutter it, but I am not particularly interested in them.

Is there a way to ignore them?

If there isn't at present, maybe something can be done to match the runtime.Callers at the printing location with the stack trace inside the error, and ignore the matching part?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pkg/errors/issues/111, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAcAzxL-p49NBbeeD4L1jhGh-9aAV7Bks5rpUgLgaJpZM4MpI3s .