This is an automated email from the ASF dual-hosted git repository.

jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 914c16eb1d1 Provide more contextual error message for PyCoder (#36825)
914c16eb1d1 is described below

commit 914c16eb1d1ecf31cb74752ab6610325a7d80230
Author: Ian Liao <[email protected]>
AuthorDate: Mon Nov 17 11:39:00 2025 -0800

    Provide more contextual error message for PyCoder (#36825)
    
    * Provide more contextual error message for coder
    
    * Fix formatting issue
    
    * Fix lint error
---
 sdks/python/apache_beam/coders/coder_impl.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/sdks/python/apache_beam/coders/coder_impl.py 
b/sdks/python/apache_beam/coders/coder_impl.py
index 35d67258b56..03514bb50db 100644
--- a/sdks/python/apache_beam/coders/coder_impl.py
+++ b/sdks/python/apache_beam/coders/coder_impl.py
@@ -1014,7 +1014,14 @@ 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 "
+          f"VarIntCoder. This coder is limited to values that fit "
+          f"within a 64-bit signed integer (-(2**63) to 2**63 - 1). "
+          f"Original error: {e}") from e
 
   def decode_from_stream(self, in_stream, nested):
     # type: (create_InputStream, bool) -> int
@@ -1036,7 +1043,13 @@ class VarIntCoderImpl(StreamCoderImpl):
   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):

Reply via email to