Skip to content

Commit 6b7aabd

Browse files
authored
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
1 parent 009290d commit 6b7aabd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

kafka/protocol/types.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
def _pack(f, value):
99
try:
1010
return pack(f, value)
11-
except error:
12-
raise ValueError(error)
13-
11+
except error as e:
12+
raise ValueError("Error encountered when attempting to convert value: "
13+
"{} to struct format: '{}', hit error: {}"
14+
.format(value, f, e))
1415

1516
def _unpack(f, data):
1617
try:
1718
(value,) = unpack(f, data)
1819
return value
19-
except error:
20-
raise ValueError(error)
21-
20+
except error as e:
21+
raise ValueError("Error encountered when attempting to convert value: "
22+
"{} to struct format: '{}', hit error: {}"
23+
.format(value, f, e))
2224

2325
class Int8(AbstractType):
2426
@classmethod

0 commit comments

Comments
 (0)