Skip to content

Commit 6d6dc17

Browse files
committed
Fix write_int and write_short type validation
It will still die, just as before, but it now includes a *helpful* error message
1 parent bb3827e commit 6d6dc17

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kafka/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77

88

99
def write_int_string(s):
10+
if s is not None and not isinstance(s, str):
11+
raise TypeError('Expected "%s" to be str\n'
12+
'data=%s' % (type(s), repr(s)))
1013
if s is None:
1114
return struct.pack('>i', -1)
1215
else:
1316
return struct.pack('>i%ds' % len(s), len(s), s)
1417

1518

1619
def write_short_string(s):
20+
if s is not None and not isinstance(s, str):
21+
raise TypeError('Expected "%s" to be str\n'
22+
'data=%s' % (type(s), repr(s)))
1723
if s is None:
1824
return struct.pack('>h', -1)
1925
elif len(s) > 32767 and sys.version < (2, 7):

0 commit comments

Comments
 (0)