mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Handle errors from
- `read_delim`
- `read_varint_prefixed_bytes`
- `decode_uvarint_from_stream`
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user