diff --git a/royalnet/bots/generic.py b/royalnet/bots/generic.py index 52574c55..b6f673f8 100644 --- a/royalnet/bots/generic.py +++ b/royalnet/bots/generic.py @@ -4,9 +4,10 @@ import asyncio import logging from ..utils import Command, NetworkHandler, Call from ..commands import NullCommand -from ..network import RoyalnetLink, Message, RequestError, RoyalnetConfig +from ..network import RoyalnetLink, Message, RoyalnetConfig from ..database import Alchemy, DatabaseConfig, relationshiplinkchain + loop = asyncio.get_event_loop() log = logging.getLogger(__name__) @@ -57,14 +58,14 @@ class GenericBot: except KeyError: _, exc, tb = sys.exc_info() log.debug(f"Missing network_handler for {message}") - return RequestError(exc=exc) + raise Exception(f"Missing network_handler for {message}") try: log.debug(f"Using {network_handler} as handler for {message}") return await getattr(network_handler, self.interface_name)(self, message) except Exception: - _, exc, tb = sys.exc_info() + _, exc, _ = sys.exc_info() log.debug(f"Exception {exc} in {network_handler}") - return RequestError(exc=exc) + raise def _init_database(self, commands: typing.List[typing.Type[Command]], database_config: DatabaseConfig): """Create an :py:class:`royalnet.database.Alchemy` with the tables required by the commands. Then, find the chain that links the ``master_table`` to the ``identity_table``.""" diff --git a/royalnet/network/messages.py b/royalnet/network/messages.py index 203316d2..132231f2 100644 --- a/royalnet/network/messages.py +++ b/royalnet/network/messages.py @@ -1,3 +1,5 @@ +import typing +import pickle from ..error import RoyalnetError @@ -56,12 +58,17 @@ class RequestSuccessful(Reply): class RequestError(Reply): """The sent request wasn't successful.""" - def __init__(self, exc: Exception): + def __init__(self, exc: typing.Optional[Exception] = None): """Create a RequestError. Parameters: exc: The exception that caused the error in the request.""" - self.exc: Exception = exc + try: + pickle.dumps(exc) + except TypeError: + self.exc: Exception = Exception(repr(exc)) + else: + self.exc = exc def raise_on_error(self) -> None: """If the reply is an error, raise an error, otherwise, do nothing.