Handling decoding errors #7
Open
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.
When the SocketServer attempts to decode messages there is the possibility of error caused by bad data.
This commit adapts the code so that any exceptions caused by decoding are captured, and a warning is logged, and the process is stopped without causing an error.
The types of errors seen were:
One could argue that these "errors" should be fixed by updating the MessageOptions module to gracefully handle such conditions, and that is definitely worth considering. By doing that, we would then be able to complete the decoding, which would allow extracting the message token which is required to identify the associated connection process.
Bad Return
This error happens because when a non repeatable option is encountered by the
MessageOptions.Decoder, it throws an exception which is not caught, resulting in theSocketServerprocess returning the error from thehandle_info/2genserver callback. This causes the process to stop, because{:error, "" is not repeatable""}is not a validhandle_info/2response.Fixing this issue would involve "catching" the exception, and ensure the SocketServer is able to return a valid response from the handle_info/2 callback.
CondClauseError
This error happens because there is no clause which returns truthy - this cond could be updated to include a base case which throws an exception.