Attaching stack traces to errors - existing library?

171 views
Skip to first unread message

Mikhail Panchenko

unread,
Apr 2, 2014, 10:49:48 PM4/2/14
to golan...@googlegroups.com
(going to try really hard not to turn this into a flamewar about Go's error handling, and I'll say up front that I have no problem with it, just trying to address a pragmatic concern)

We've found ourselves having a bit of a problem: all of our code religiously checks errors. However things usually take one of two routes: either the errors are just dutifully returned up the stack as is, OR the errors are wrapped in an additional layer of "context" at each (or at least one..) level by way of fmt.Errorf("Error doing X: %s", err). The former is obviously bewildering when discovered, especially since some of the error messages in both the standard library and libraries we depend on are rather terse. The latter makes it very easy to track your way back down the stack, assuming everyone was disciplined, but is deeply unsatisfying - you end up with a stack trace in prose, having to grep your way back to the lines on which the prose was composed.

I don't believe Go needs to change anything about its error handling or introduce exceptions, and panics seem a bit heavy handed for things like connection pool exhaustion (things that are very unexception and normal). So I started thinking about a potential library to make it easy to attach a stack trace to an error object. I noticed that this idea had been mentioned by Andrew Gerrand as an "idea" at the bottom of this excellent post http://blog.golang.org/error-handling-and-go. I read each one of those ideas as "At Google, we have a library for..." :)

So, after all that, my very simple question, before I write the code, is: has anyone already done this in an OSS library?

Thanks!

Dan Kortschak

unread,
Apr 3, 2014, 12:19:28 AM4/3/14
to Mikhail Panchenko, golan...@googlegroups.com
Have you looked at Roger Peppe's package: github.com/juju/errgo/errors

There is also one in my library: code.google.com/p/biogo/errors

Rodrigo Kochenburger

unread,
Apr 3, 2014, 3:05:30 PM4/3/14
to Dan Kortschak, Mikhail Panchenko, golan...@googlegroups.com

- RK


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages