From 153e6f4e07bdaf32d6acf1ef420c5a3acb26cd5f Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Fri, 5 Jul 2024 20:20:36 -0400 Subject: [PATCH] Better RLP error message for mismatched element count --- src/ethereum/rlp.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ethereum/rlp.py b/src/ethereum/rlp.py index 7fcc85335c..3ada0f4fac 100644 --- a/src/ethereum/rlp.py +++ b/src/ethereum/rlp.py @@ -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] = {}