-
Notifications
You must be signed in to change notification settings - Fork 28
Handle unknown event types gracefully instead of crashing #680
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -381,7 +381,7 @@ def serialize_members(self, serializer: ShapeSerializer): | |||||
|
|
||||||
|
|
||||||
| @dataclass | ||||||
| class EventStreamUnknownEvent: | ||||||
| class EventStreamUnknown: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the name change here?
Suggested change
|
||||||
| tag: str | ||||||
|
|
||||||
| def serialize(self, serializer: ShapeSerializer): | ||||||
|
|
@@ -396,7 +396,7 @@ def serialize_members(self, serializer: ShapeSerializer): | |||||
| | EventStreamPayloadEvent | ||||||
| | EventStreamBlobPayloadEvent | ||||||
| | EventStreamErrorEvent | ||||||
| | EventStreamUnknownEvent | ||||||
| | EventStreamUnknown | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modified this because the generated code does not have "Event" suffix after "Unknown". |
||||||
| ) | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -429,7 +429,7 @@ def _consumer(self, schema: Schema, de: ShapeDeserializer) -> None: | |||||
| self._set_result(EventStreamErrorEvent(ErrorEvent.deserialize(de))) | ||||||
|
|
||||||
| case _: | ||||||
| raise SmithyError(f"Unexpected member schema: {schema}") | ||||||
| self._set_result(EventStreamUnknown(tag=schema.expect_member_name())) | ||||||
|
|
||||||
| def _set_result(self, value: EventStream) -> None: | ||||||
| if self._result is not None: | ||||||
|
|
@@ -635,6 +635,19 @@ def _consumer(schema: Schema, de: ShapeDeserializer) -> None: | |||||
| ] | ||||||
|
|
||||||
|
|
||||||
| UNKNOWN_EVENT_CASE = ( | ||||||
| EventStreamUnknown(tag="unmodeledEvent"), | ||||||
| EventMessage( | ||||||
| headers={ | ||||||
| ":message-type": "event", | ||||||
| ":event-type": "unmodeledEvent", | ||||||
| ":content-type": "application/json", | ||||||
| }, | ||||||
| payload=b"{}", | ||||||
| ), | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| INITIAL_REQUEST_CASE = ( | ||||||
| EventStreamOperationInputOutput(message="The initial request!"), | ||||||
| EventMessage( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||
| EventStreamDeserializer, | ||||||
| EventStreamErrorEvent, | ||||||
| EventStreamOperationInputOutput, | ||||||
| EventStreamUnknown, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not add "Event" at the end because the generated code does not have "Event" suffix after "Unknown". |
||||||
| ) | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -126,3 +127,20 @@ async def test_read_closed_receiver_source() -> None: | |||||
| with pytest.raises(IOError): | ||||||
| await receiver.receive() | ||||||
| assert receiver.closed | ||||||
|
|
||||||
|
|
||||||
| def test_deserialize_unknown_event_type(): | ||||||
| message = EventMessage( | ||||||
| headers={ | ||||||
| ":message-type": "event", | ||||||
| ":event-type": "unmodeledEvent", | ||||||
| ":content-type": "application/json", | ||||||
| }, | ||||||
| payload=b"{}", | ||||||
| ) | ||||||
| source = Event.decode(BytesIO(message.encode())) | ||||||
| assert source is not None | ||||||
| deserializer = EventDeserializer(event=source, payload_codec=JSONCodec()) | ||||||
| result = EventStreamDeserializer().deserialize(deserializer) | ||||||
| assert isinstance(result, EventStreamUnknown) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not add "Event" at the end because the generated code does not have "Event" suffix after "Unknown". |
||||||
| assert result.tag == "unmodeledEvent" | ||||||
Uh oh!
There was an error while loading. Please reload this page.