Add exception raised to docstring

This commit is contained in:
NIC619
2019-09-19 22:19:36 +08:00
parent c6294ad19b
commit 7fc958e7be
8 changed files with 29 additions and 10 deletions

View File

@ -37,7 +37,7 @@ class Multiselect(IMultiselectMuxer):
Negotiate performs protocol selection
:param stream: stream to negotiate on
:return: selected protocol name, handler function
:raise Exception: negotiation failed exception
:raise MultiselectError: raised when negotiation failed
"""
# Perform handshake to ensure multiselect protocol IDs match
@ -49,7 +49,7 @@ class Multiselect(IMultiselectMuxer):
try:
command = await communicator.read()
except MultiselectCommunicatorError as error:
raise MultiselectError(str(error))
raise MultiselectError(error)
# Command is ls or a protocol
if command == "ls":
@ -76,7 +76,7 @@ class Multiselect(IMultiselectMuxer):
"""
Perform handshake to agree on multiselect protocol
:param communicator: communicator to use
:raise Exception: error in handshake
:raise MultiselectError: raised when handshake failed
"""
# TODO: Use format used by go repo for messages
@ -91,7 +91,7 @@ class Multiselect(IMultiselectMuxer):
try:
handshake_contents = await communicator.read()
except MultiselectCommunicatorError as error:
raise MultiselectError(str(error))
raise MultiselectError(error)
# Confirm that the protocols are the same
if not validate_handshake(handshake_contents):

View File

@ -21,7 +21,7 @@ class MultiselectClient(IMultiselectClient):
Ensure that the client and multiselect
are both using the same multiselect protocol
:param stream: stream to communicate with multiselect over
:raise Exception: multiselect protocol ID mismatch
:raise MultiselectClientError: raised when handshake failed
"""
# TODO: Use format used by go repo for messages
@ -54,6 +54,7 @@ class MultiselectClient(IMultiselectClient):
:param protocol: protocol to select
:param stream: stream to communicate with multiselect over
:return: selected protocol
:raise MultiselectClientError: raised when protocol negotiation failed
"""
# Perform handshake to ensure multiselect protocol IDs match
await self.handshake(communicator)
@ -77,7 +78,7 @@ class MultiselectClient(IMultiselectClient):
Try to select the given protocol or raise exception if fails
:param communicator: communicator to use to communicate with counterparty
:param protocol: protocol to select
:raise Exception: error in protocol selection
:raise MultiselectClientError: raised when protocol negotiation failed
:return: selected protocol
"""

View File

@ -14,6 +14,9 @@ class MultiselectCommunicator(IMultiselectCommunicator):
self.read_writer = read_writer
async def write(self, msg_str: str) -> None:
"""
:raise MultiselectCommunicatorError: raised when failed to write to underlying reader
"""
msg_bytes = encode_delim(msg_str.encode())
try:
await self.read_writer.write(msg_bytes)
@ -23,6 +26,9 @@ class MultiselectCommunicator(IMultiselectCommunicator):
)
async def read(self) -> str:
"""
:raise MultiselectCommunicatorError: raised when failed to read from underlying reader
"""
try:
data = await read_delim(self.read_writer)
# `IOException` includes `IncompleteReadError` and `StreamError`