Skip to content

Commit

Permalink
[FIX] FileBasedPacketSerializer: Fixed delayed IncrementalDeserialize…
Browse files Browse the repository at this point in the history
…Error
  • Loading branch information
francis-clairicia committed Nov 9, 2023
1 parent f51d113 commit 87b726c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/easynetwork/serializers/base_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,9 @@ def incremental_deserialize(self) -> Generator[None, bytes, tuple[_DTOPacketT, b
except EOFError:
continue
except self.__expected_errors as exc:
remaining_data: bytes = buffer.read()
if not remaining_data: # Possibly an EOF error, give it a chance
continue
raise IncrementalDeserializeError(
f"Deserialize error: {exc}",
remaining_data=remaining_data,
remaining_data=buffer.read(),
error_info={"data": buffer.getvalue()},
) from exc
else:
Expand Down
9 changes: 4 additions & 5 deletions tests/unit_test/test_serializers/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,11 @@ def side_effect(file: IO[bytes]) -> Any:
consumer.send(b"d")
consumer.send(b"a")
consumer.send(b"t")
consumer.send(b"a") # MyFileAPIValueError was raised but there is no remaining data, so it must continue
with pytest.raises(IncrementalDeserializeError) as exc_info: # There is new data and error still here
consumer.send(b"other")
with pytest.raises(IncrementalDeserializeError) as exc_info:
consumer.send(b"a")
exception = exc_info.value

# Assert
assert exception.remaining_data == b"other"
assert exception.remaining_data == b""
assert type(exception.__cause__) is MyFileAPIValueError
assert exception.error_info == {"data": b"dataother"}
assert exception.error_info == {"data": b"data"}

0 comments on commit 87b726c

Please sign in to comment.