diff --git a/libp2p/utils.py b/libp2p/utils.py index 4844f0e1..39c79e58 100644 --- a/libp2p/utils.py +++ b/libp2p/utils.py @@ -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]