diff options
author | Jeff Widman <jeff@jeffwidman.com> | 2017-12-07 18:15:53 -0800 |
---|---|---|
committer | Jeff Widman <jeff@jeffwidman.com> | 2017-12-07 18:18:23 -0800 |
commit | 54f12d476cf3c774d985db7f28d1a7ab996f1963 (patch) | |
tree | 3a7eda84406c4ab48eeb27043e312e0eb737ae14 | |
parent | 009290ddd5d4616d70bff93f841e773af8b22750 (diff) | |
download | kafka-python-better-struct-errors.tar.gz |
Give better struct errorsbetter-struct-errors
Stop shadowing the word `error` because we want to know what the
specific exception message was.
Also give more details on exactly which value failed. We don't know who
submitted the value, but perhaps it's unique enough that we can debug it better.
Fix #1318
-rw-r--r-- | kafka/protocol/types.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/kafka/protocol/types.py b/kafka/protocol/types.py index 22b49a4..516b957 100644 --- a/kafka/protocol/types.py +++ b/kafka/protocol/types.py @@ -8,16 +8,20 @@ from .abstract import AbstractType def _pack(f, value): try: return pack(f, value) - except error: - raise ValueError(error) + except error as e: + raise ValueError("Error encountered when attempting to convert value: " + "{} to struct format: '{}', hit error: {}" + .format(value, f, e)) def _unpack(f, data): try: (value,) = unpack(f, data) return value - except error: - raise ValueError(error) + except error as e: + raise ValueError("Error encountered when attempting to convert value: " + "{} to struct format: '{}', hit error: {}" + .format(value, f, e)) class Int8(AbstractType): |