forked from tpitale/coap_ex
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling decoding errors #7
Open
zolakeith
wants to merge
3
commits into
master
Choose a base branch
from
ks/bad_return_value
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
zolakeith
force-pushed
the
ks/bad_return_value
branch
from
August 21, 2024 13:09
522b247
to
f8c1396
Compare
zolakeith
force-pushed
the
ks/bad_return_value
branch
from
August 21, 2024 13:41
f8c1396
to
7581dca
Compare
zolakeith
commented
Aug 21, 2024
zolakeith
commented
Aug 21, 2024
zolakeith
commented
Aug 21, 2024
zolakeith
force-pushed
the
ks/bad_return_value
branch
from
August 21, 2024 13:52
7581dca
to
dbcd5ef
Compare
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: - bad return value: {:error, "" is not repeatable""} - (CondClauseError) no cond clause evaluated to a truthy value (coap_ex 0.1.0) lib/coap/message_options.ex - (CaseClauseError) no case clause matching <<...>> (coap_ex 0.1.0) lib/coap/message_options.ex:54 - (FunctionClauseError) no function clause matching in CoAP.Block.decode/1 - (MatchError) no match of right hand side value: """" It might be better to update the MessageOptions module to handle these errors gracefully by throwing a controlled exception. This exception could then be caught by the SocketServer, allowing it to return a relevant error along with the partially decoded message. This approach would enable the SocketServer to potentially identify the connection and send an appropriate error message to the client.
zolakeith
force-pushed
the
ks/bad_return_value
branch
from
August 21, 2024 15:01
dbcd5ef
to
35cb537
Compare
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.
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 theSocketServer
process returning the error from thehandle_info/2
genserver callback. This causes the process to stop, because{:error, "" is not repeatable""}
is not a validhandle_info/2
response.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.