honeybadger-io / honeybadger-go

Send Go (golang) panics and errors to Honeybadger.
https://www.honeybadger.io/
MIT License
34 stars 15 forks source link

Add Recover() function to recover, alert and continue from panics #28

Closed jgeiger closed 6 years ago

jgeiger commented 6 years ago

It would be nice to add a honeybadger.Recover() that would recover a panic, send the notification and let the app continue. This could be used in goroutines in a single run CLI app where we don't want to crash if a single goroutine had an issue.

lostghost commented 6 years ago

I don't believe that this should be added to the honeybadger-go library. The concern over logging a panic and choosing to recover from it are separate concerns and should be handled separately. Additionally, I would expect that in most cases, the recovery process would be specific to the application and would need to do additional work to return the system to a stable state in order to resume work.

All of that is already able to be accomplished with the features of the existing library.

func main() {
    defer func() {
        if err := recover(); err != nil {
            // return application to usable state and resume
        }
    }()

    defer honeybadger.Monitor()

    // Do some stuff that might panic
}
joshuap commented 6 years ago

I agree with @lostghost; seems like something that can (and should) be handled in the application code. Thanks for the ideas to both of you!