Wrap functions with arguments, and add Rollbar to defer/recover functions#66
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WrapandWrapAndWaitare convenient for reporting unhandled panics in wrapped functions, but until now could only wrap functions with no arguments and no return values. This PR allows any function signature to be used. It also exposes a new helper,LogPanic, that can be used to add Rollbar reporting to any defer/recover function.Since wrapping a function in main() won't recover panics in goroutines, and since many programs do use goroutines liberally, this extra flexibility should help make it easier to report panics wherever needed.
The updated
WrapandWrapAndWaitare fully compatible with previous/existing behavior, acceptingfunc()just fine, and the existing behavior of returning the error is preserved.While
WrapandWrapAndWaitcan now accept functions with any return signature, they do not return the function's return value. In cases where this is needed, theLogPanichelper can be used to add Rollbar to the function's defer/recover handler, instead of using any wrapper. UsingLogPanicmakes the resulting defer function simple and compact:An even more streamlined
defer RollbarRecover()helper was considered, butrecover()only works correctly when in a closure of the containing function, not when the defer function is a separate non-closure function.