Skip to content

Commit 54f12d4

Browse files
committed
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 54f12d4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

kafka/protocol/types.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
def _pack(f, value):
99
try:
1010
return pack(f, value)
11-
except error:
12-
raise ValueError(error)
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))
1315

1416

1517
def _unpack(f, data):
1618
try:
1719
(value,) = unpack(f, data)
1820
return value
19-
except error:
20-
raise ValueError(error)
21+
except error as e:
22+
raise ValueError("Error encountered when attempting to convert value: "
23+
"{} to struct format: '{}', hit error: {}"
24+
.format(value, f, e))
2125

2226

2327
class Int8(AbstractType):

0 commit comments

Comments
 (0)