1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Fix bot getting stuck on downloads

This commit is contained in:
Steffo 2019-05-05 16:58:24 +02:00
parent 7fa429335c
commit 21089c94c9
2 changed files with 14 additions and 6 deletions

View file

@ -4,9 +4,10 @@ import asyncio
import logging import logging
from ..utils import Command, NetworkHandler, Call from ..utils import Command, NetworkHandler, Call
from ..commands import NullCommand from ..commands import NullCommand
from ..network import RoyalnetLink, Message, RequestError, RoyalnetConfig from ..network import RoyalnetLink, Message, RoyalnetConfig
from ..database import Alchemy, DatabaseConfig, relationshiplinkchain from ..database import Alchemy, DatabaseConfig, relationshiplinkchain
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -57,14 +58,14 @@ class GenericBot:
except KeyError: except KeyError:
_, exc, tb = sys.exc_info() _, exc, tb = sys.exc_info()
log.debug(f"Missing network_handler for {message}") log.debug(f"Missing network_handler for {message}")
return RequestError(exc=exc) raise Exception(f"Missing network_handler for {message}")
try: try:
log.debug(f"Using {network_handler} as handler for {message}") log.debug(f"Using {network_handler} as handler for {message}")
return await getattr(network_handler, self.interface_name)(self, message) return await getattr(network_handler, self.interface_name)(self, message)
except Exception: except Exception:
_, exc, tb = sys.exc_info() _, exc, _ = sys.exc_info()
log.debug(f"Exception {exc} in {network_handler}") 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): 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``.""" """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``."""

View file

@ -1,3 +1,5 @@
import typing
import pickle
from ..error import RoyalnetError from ..error import RoyalnetError
@ -56,12 +58,17 @@ class RequestSuccessful(Reply):
class RequestError(Reply): class RequestError(Reply):
"""The sent request wasn't successful.""" """The sent request wasn't successful."""
def __init__(self, exc: Exception): def __init__(self, exc: typing.Optional[Exception] = None):
"""Create a RequestError. """Create a RequestError.
Parameters: Parameters:
exc: The exception that caused the error in the request.""" 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: def raise_on_error(self) -> None:
"""If the reply is an error, raise an error, otherwise, do nothing. """If the reply is an error, raise an error, otherwise, do nothing.