Skip to content

Commit f4bcdc9

Browse files
aherlihybehackett
authored andcommitted
PYTHON-940 - Unhelpful and pretty wrong error message.
1 parent 1e7ebb1 commit f4bcdc9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pymongo/network.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ def receive_message(sock, operation, request_id):
6060
header = _receive_data_on_socket(sock, 16)
6161
length = _UNPACK_INT(header[:4])[0]
6262

63+
actual_op = _UNPACK_INT(header[12:])[0]
64+
assert operation == actual_op, ("wire protocol error: "
65+
"unknown opcode %r" % (actual_op,))
6366
# No request_id for exhaust cursor "getMore".
6467
if request_id is not None:
6568
response_id = _UNPACK_INT(header[8:12])[0]
66-
assert request_id == response_id, "ids don't match %r %r" % (
67-
request_id, response_id)
69+
assert request_id == response_id, (
70+
"wire protocol error: got response id %r but expected %r"
71+
% (response_id, request_id))
72+
73+
assert length > 16, ("wire protocol error: message length is shorter"
74+
" than standard message header: %r" % (length,))
6875

69-
assert operation == _UNPACK_INT(header[12:])[0]
7076
return _receive_data_on_socket(sock, length - 16)
7177

7278

0 commit comments

Comments
 (0)