Handle errors from

- `read_delim`
    - `read_varint_prefixed_bytes`
    - `decode_uvarint_from_stream`
This commit is contained in:
NIC619
2019-09-15 16:58:08 +08:00
parent 905a473ac3
commit 879f193aa1
4 changed files with 34 additions and 11 deletions

View File

@ -1,6 +1,9 @@
from libp2p.exceptions import ParseError
from libp2p.io.abc import ReadWriteCloser
from libp2p.io.exceptions import IOException
from libp2p.utils import encode_delim, read_delim
from .exceptions import MultiselectCommunicatorError
from .multiselect_communicator_interface import IMultiselectCommunicator
@ -15,5 +18,11 @@ class MultiselectCommunicator(IMultiselectCommunicator):
await self.read_writer.write(msg_bytes)
async def read(self) -> str:
data = await read_delim(self.read_writer)
try:
data = await read_delim(self.read_writer)
# `IOException` includes `IncompleteReadError` and `StreamError`
except (ParseError, IOException, ValueError):
raise MultiselectCommunicatorError(
"fail to read from multiselect communicator"
)
return data.decode()