Raise read_delim exception with different msgs

Separate `len(msg_bytes) == 0` and `msg_bytes[-1:] != b"\n"`, to raise
`ParseError` with different messages.
This commit is contained in:
mhchia 2019-09-24 13:22:25 +08:00
parent 37bee9fb16
commit 7405f078e6
No known key found for this signature in database
GPG Key ID: 389EFBEA1362589A

View File

@ -73,8 +73,12 @@ def encode_delim(msg: bytes) -> bytes:
async def read_delim(reader: Reader) -> bytes:
msg_bytes = await read_varint_prefixed_bytes(reader)
if len(msg_bytes) == 0 or msg_bytes[-1:] != b"\n":
raise ParseError(f'msg_bytes is not delimited by b"\\n": msg_bytes={msg_bytes}')
if len(msg_bytes) == 0:
raise ParseError(f"`len(msg_bytes)` should not be 0")
if msg_bytes[-1:] != b"\n":
raise ParseError(
f'`msg_bytes` is not delimited by b"\\n": `msg_bytes`={msg_bytes}'
)
return msg_bytes[:-1]