Skip to content
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

[LG-71] Improvements to error handling #26

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

sgunes-wirepas
Copy link
Contributor

@sgunes-wirepas sgunes-wirepas commented Nov 13, 2024

Includes 2 main changes:

  1. .from_payload() calls now will raise an exception if a message with different type is given. For example when calling GetConfigsRequest.from_payload() with a message missing GenericMessage::wirepas::get_configs_req.

  2. If SetScratchpadTargetAndActionRequest.from_payload() fails due to message contents (such as too large target sequence), it would raise a new InvalidMessageContents exception which contains the request header in it. This would make it possible to construct a response with the right request id.

This refactoring is made in order to make it easier to introduce
stricter checks during message decoding.

Request, Response, and Event classes are now inheriting the
WirepasMessage class. The class handles decoding of a message using the
_get_related_message() method which should be implemented by each child
class.
Earlier, it was possible that a protobuf payload not including a certain
message was decoded using .from_payload(). For example when using
GetConfigsRequest.from_payload() with a message missing
GenericMessage::wirepas::get_configs_req, the library was not reporting
an error and setting the req_id to 0 even though it was not initialized
in the protobuf message.

If that happens now, and InvalidMessageType exception is raised. This
exception has the GatewayAPIParsingException as its parent to help with
backwards compatibility.

Also refactoring the tests and having a new test file for decoding
related error testing.
If constructing a new SetScratchpadTargetAndActionRequest from payload
fails due to invalid values, a new InvalidMessageContents exception is
raised. This exception can hold the header of the request message, and
it would be possible to generate a response with the corresponding
req_id based on the exception.
@sgunes-wirepas sgunes-wirepas changed the title Fix/lg 71 [LG-71] Improvements to error handling Nov 22, 2024
@sgunes-wirepas sgunes-wirepas marked this pull request as ready for review November 22, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant