From 21089c94c9dac601bc42dea1cb32642b895bef35 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 5 May 2019 16:58:24 +0200 Subject: [PATCH] Fix bot getting stuck on downloads --- royalnet/bots/generic.py | 9 +++++---- royalnet/network/messages.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) 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.