Skip to content

Commit

Permalink
reduce truncation in errors (#166)
Browse files Browse the repository at this point in the history
* reduce truncation in errors

allow more int values to be fully printed in errors. the current code
truncates a lot of integer values which fit in 256 bits, which reduces
helpfulness of the error message when debugging.

* Fix tests, remove one that was a duplicate test of logic

* Add newsfragment

Co-authored-by: kclowes <kclowes@users.noreply.github.com>
  • Loading branch information
charles-cooper and kclowes committed Jul 13, 2022
1 parent ec29bee commit 7f259cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eth_abi/utils/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
)


def abbr(value: Any, limit: int = 20) -> str:
def abbr(value: Any, limit: int = 79) -> str:
"""
Converts a value into its string representation and abbreviates that
representation based on the given length `limit` if necessary.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/166.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce truncation in errors
27 changes: 17 additions & 10 deletions tests/utils/test_abbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@


@pytest.mark.parametrize(
'value,expected,limit',
"value,expected,limit",
(
(1234567891234567891, '1234567891234567891', None),
(12345678912345678912, '12345678912345678912', None),
(123456789123456789123, '12345678912345678...', None),
('asdf' * 30, "'asdfasdfasdfasdf...", None),
(list(range(100)), '[0, 1, 2, 3, 4, 5...', None),
(1234567891234567891, '...', 3),
(1234567891234567891, '1...', 4),
)
(1234567891234567891, "1234567891234567891", None),
(12345678912345678912, "12345678912345678912", None),
(
"asdf" * 30,
"'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd...",
None,
),
(
list(range(100)),
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2...", # noqa: E501
None,
),
(1234567891234567891, "...", 3),
(1234567891234567891, "1...", 4),
),
)
def test_abbr(value, expected, limit):
if limit is not None:
Expand All @@ -27,4 +34,4 @@ def test_abbr(value, expected, limit):

def test_abbr_throws_value_errors():
with pytest.raises(ValueError):
abbr('asdf', limit=2)
abbr("asdf", limit=2)

0 comments on commit 7f259cb

Please sign in to comment.