Raise ParseError in read_delim

This commit is contained in:
mhchia
2019-09-23 16:01:22 +08:00
parent 92deae41dc
commit 95ae718e3d
3 changed files with 6 additions and 8 deletions

View File

@ -73,9 +73,8 @@ def encode_delim(msg: bytes) -> bytes:
async def read_delim(reader: Reader) -> bytes:
msg_bytes = await read_varint_prefixed_bytes(reader)
# TODO: Investigate if it is possible to have empty `msg_bytes`
if len(msg_bytes) != 0 and msg_bytes[-1:] != b"\n":
raise ValueError(f'msg_bytes is not delimited by b"\\n": msg_bytes={msg_bytes}')
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}')
return msg_bytes[:-1]