Controller unhandled errors should be passed as BadStatus to interceptors #184
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.
While using
Gruf::Interceptors::Instrumentation::RequestLogging::Interceptor
, I noticed that in the event of unhandled errors raised in my controller (errors that are not of typeGRPC::BadStatus
or raised viafail!
), I was not getting any request logging in my log.In a successful controller call I would get something like:
If an unhandled error was raised I would get nothing.
My assumption is that I should still get logging in that case. Request info is useful to have, including when an unhandled error occurs.
Investingating why I wasn't getting any, I observed that in
Gruf::Interceptors::Instrumentation::RequestLogging::Interceptor
, the interceptor yields to the controller via this line:Gruf::Interceptors::Timer.time
knows torescue
and handle errors, but only of typeGRPC::BadStatus
. I realized that unhandled errors would not be caught by it, hence the error logging interceptor would get exited right there and never log.I noticed that the base controller code turns unhandled errors in the
GRPC::BadStatus
errors. But it only does so after all the interceptors have run (or been tripped as above). I thought why not just do this before the interceptors. Seeing how the logging interceptor is designed, maybe it was even meant to be that way. So this is what I propose here.It works well for me so far.
API changes:
GRPC::BadStatus
error in the case of unhandled errors, instead of the original unhandled error. To reach the original error,GRPC::BadStatus#cause
can be used.