Skip to content

Commit

Permalink
Better RLP error message for mismatched element count
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn committed Jul 6, 2024
1 parent 656e3d2 commit 29ee30f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ethereum/rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,15 @@ def _deserialize_to_dataclass(cls: Type[U], decoded: Simple) -> U:
target_fields = fields(cls)

if isinstance(decoded, bytes):
raise RLPDecodingError
raise RLPDecodingError(f"got `bytes` while decoding `{cls.__name__}`")

if len(target_fields) != len(decoded):
raise RLPDecodingError
name = cls.__name__
actual = len(decoded)
expected = len(target_fields)
raise RLPDecodingError(
f"`{name}` needs {expected} field(s), but got {actual} instead"
)

values: Dict[str, Any] = {}

Expand Down

0 comments on commit 29ee30f

Please sign in to comment.