From 54f12d476cf3c774d985db7f28d1a7ab996f1963 Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Thu, 7 Dec 2017 18:15:53 -0800 Subject: Give better 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 --- kafka/protocol/types.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'kafka/protocol') 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): -- cgit v1.2.1