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

IncrementalDeserializeError.remaining_data is no longer reset #170

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/easynetwork/lowlevel/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def __next__(self) -> _ReceivedPacketT:
packet, remaining = exc.value
remaining = _ensure_bytes(remaining)
except StreamProtocolParseError as exc:
remaining, exc.remaining_data = exc.remaining_data, b""
remaining = _ensure_bytes(remaining)
self.__b = remaining
self.__b = _ensure_bytes(exc.remaining_data)
raise
except Exception as exc:
raise RuntimeError("protocol.build_packet_from_chunks() crashed") from exc
Expand Down
3 changes: 1 addition & 2 deletions src/easynetwork/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ def build_packet_from_chunks(self) -> Generator[None, bytes, tuple[_ReceivedPack
try:
packet, remaining_data = yield from self.__serializer.incremental_deserialize()
except IncrementalDeserializeError as exc:
remaining_data, exc.remaining_data = exc.remaining_data, b""
raise StreamProtocolParseError(remaining_data, exc) from exc
raise StreamProtocolParseError(exc.remaining_data, exc) from exc
except DeserializeError as exc:
raise RuntimeError("DeserializeError raised instead of IncrementalDeserializeError") from exc

Expand Down
1 change: 1 addition & 0 deletions tests/unit_test/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def test____build_packet_from_chunks____deserialize_error(
mock_convert_func.assert_not_called()
assert isinstance(exception.error, IncrementalDeserializeError)
assert exception.remaining_data is mocker.sentinel.chunk
assert exception.error.remaining_data is mocker.sentinel.chunk
assert isinstance(exception.__cause__, IncrementalDeserializeError)

def test____build_packet_from_chunks____wrong_deserialize_error(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_test/test_tools/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def side_effect() -> Generator[None, bytes, tuple[Any, bytes]]:
# Assert
mock_build_packet_from_chunks_func.assert_called_once_with()
assert consumer.get_buffer() == b"World"
assert exception.remaining_data == b""
assert exception.remaining_data == b"World"

def test____next____generator_did_not_yield(
self,
Expand Down