Skip to content

Commit

Permalink
Add better overflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Feb 21, 2024
1 parent abe1615 commit 0454264
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tivars/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ def set(cls, value: _T, *, length: int = None, **kwargs) -> bytes:
:return: The little-endian representation of ``value``
"""

return int.to_bytes(value, length if length is not None else 2, 'little')
length = length if length is not None else 2
try:
return int.to_bytes(value, length, 'little')

except OverflowError:
raise OverflowError(f"{value} cannot fit in a field of width {length}")


class String(Converter):
Expand Down

0 comments on commit 0454264

Please sign in to comment.