go-res
go-res copied to clipboard
Panic not recovered within With
Issue
When there is a panic within a With
callback, the service will currently crash. This means using RequireValue
, which panics if the Get handler returns an error, will be very dangerous within a With
callback.
Example
s.With("library.book.1337", func(r res.Resource) {
// Since RequireValue will panic if the Get handler
// returns a NotFound error, the entire service will crash.
book := r.RequireValue.(*Book)
})
Solution
Any panic that happens within the With
callback should be recovered and logged as an error.
Since it the callback is (most likely) running on a different goroutine than the caller of With
, it will not be possible to return any recovered panic as an error on the With
call.