Add server-side logging of non-Thrift exceptions. #186
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.
BACKGROUND
Two kinds of exceptions can be thrown by a handler processing a Thrift request:
exceptions
in a .thrift file. The server serializes them and sends them to the client. Clients should expect them to happen from time to time and should handle them gracefully.TApplicationException
to the client containing the message from the exception.THIS CHANGE
I modifed the code that generates the server processor to include a console.error() statement that logs exception messages and stack traces when a handler throws a non-Thrift exception. Previously there was no server-side logging for non-Thrift exceptions. The message was sent to the client and the stack trace was discarded entirely. This is not sufficient. Even if you have the exception message received by the client that may not be enough to determine where the error happened. And if you don't control the client then you're REALLY out of luck.
There are no other calls to console.log() or console.error() in the generated code. It could be argued that it's bad form for the generated code to use console.error() since it's sort of like a library, but I think it's more important to log the exception. A better solution might be to allow server implementors to provide a callback function for logging, but I leave that as an exercise for a future developer.
I updated both the Apache code and the thrift-server code, and the tests for both.
Here's the diff of a
ping
function generated for thrift-server before and after this change: