Skip to content

Commit b607ef1

Browse files
authored
PYTHON-5214 - Improve BSON decoding InvalidBSON error message (#2605)
1 parent fd02550 commit b607ef1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bson/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,9 @@ def _decode_all(data: _ReadableBuffer, opts: CodecOptions[_DocumentType]) -> lis
11091109
while position < end:
11101110
obj_size = _UNPACK_INT_FROM(data, position)[0]
11111111
if data_len - position < obj_size:
1112-
raise InvalidBSON("invalid object size")
1112+
raise InvalidBSON(
1113+
f"invalid object size: expected {obj_size}, got {data_len - position}"
1114+
)
11131115
obj_end = position + obj_size - 1
11141116
if data[obj_end] != 0:
11151117
raise InvalidBSON("bad eoo")

0 commit comments

Comments
 (0)