Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions sdks/python/apache_beam/coders/coder_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,13 @@ class VarIntCoderImpl(StreamCoderImpl):
A coder for int objects."""
def encode_to_stream(self, value, out, nested):
# type: (int, create_OutputStream, bool) -> None
out.write_var_int64(value)
try:
out.write_var_int64(value)
except OverflowError as e:
raise OverflowError(
f"Integer value '{value}' is out of the encodable range for VarIntCoder. "
f"This coder is limited to values that fit within a 64-bit signed integer "
f"(-(2**63) to 2**63 - 1). Original error: {e}") from e

def decode_from_stream(self, in_stream, nested):
# type: (create_InputStream, bool) -> int
Expand All @@ -1036,7 +1042,13 @@ def decode(self, encoded):
def estimate_size(self, value, nested=False):
# type: (Any, bool) -> int
# Note that VarInts are encoded the same way regardless of nesting.
return get_varint_size(value)
try:
return get_varint_size(value)
except OverflowError as e:
raise OverflowError(
f"Cannot estimate size for integer value '{value}'. "
f"Value is out of the range for VarIntCoder (64-bit signed integer). "
f"Original error: {e}") from e


class VarInt32CoderImpl(StreamCoderImpl):
Expand Down
Loading