Golang raven library


Hi, I’m fairly new to both Go and Sentry and have been using this on my first project. I have a couple of questions regarding raven.RecoveryHandler:

  1. Is this for handling panics? How is it different from CapturePanic? I know it’s meant to be used with http but I’m not sure why I can’t just wrap http.ServeAndListen in CapturePanic.

  2. Is there a way I can use RecoveryHandler as a middleware in the alice package so I don’t have to wrap it on every one of my handler functions? The type of RecoveryHandler is not compatible with what alice.New() wants but I suppose there are ways to bridge them.

Thank you very much!


I did not work on the go library myself but my understanding from what it does currently is that

  1. RecoveryHandler is specifically for net/http
  2. I do not believe this is possible but I am not sure how alice works.

I think as far as go is concerned our abilities to provide improved support is a bit hampered by the language itself. It would be great to get feedback about how people thinking we could improve the ergonomics of the library however.


Hello mitsuhiko,

I did some more reading including the source code of both CapturePanic and RecoveryHandler and I think I now understand why RecoveryHandler is needed. http.ListenAndServe has an internal panic recovery mechanism, so it will never crash even if the handlers panic (panics in goroutines aside, that’s a different topic). Therefore, wrapping http.ListenAndServe in a CapturePanic will never hit the code of CapturePanic and we won’t be able to log the exceptions.

The need to wrap RecoveryHandler on every single one of my http handler functions is still a big hassle. I was hoping there’s a better way, but I don’t know enough about Go to know how to convert it into a middleware.
In most middleware packages, the signature is a func (http.Handler) http.Handler, which works very well with alice and other middleware wrapper libraries. RecoveryHandler, however, has a signature that’s incompatible.


Have a look at the very end of this article:

Section “Let’s write another middleware: Panic recovery”

This is almost the exact code of raven.RecoveryHandler but in a signature that is compatible with middleware chaining.

Is this something you guys can do?


Yeah, so I wrote this a long time ago and I was a bit torn on literally naming here.

So RecoveryHandler is meant to work with http.HandleFunc, not http.Handle. I could relatively easily add something here to support the signature of http.Handle to better accommodate middleware patterns.

In retrospect, should have named it RecoveryHandleFunc. :frowning: