From 2ba6fb17ca4b535f00dac4758546fabfedf1ed16 Mon Sep 17 00:00:00 2001 From: Draper <27962761+Drapersniper@users.noreply.github.com> Date: Tue, 22 Oct 2019 03:36:24 +0100 Subject: [PATCH] [Audio] Handle Missing SQL deps more gracefully (#3066) * Removes `MAX_BALANCE` from bank, user `bank.get_max_balance()` now `[p]bankset maxbal` can be used to set the maximum bank balance Signed-off-by: Guy * Remove duplicated call in `[p]playlist update` Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Handle both ModuleNotFoundError and ImportError and pull a more complete error message to forward to the user and fix grammar. Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Since we aren't 100% certain of message length here due to using the error message for the raised error ... lets use pagify so this doesn't bite us in the future. Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * .... Lets not reinvent the wheel Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Address Jack's review --- changelog.d/audio/3065.bugfix.rst | 1 + redbot/cogs/audio/apis.py | 8 ++++++-- redbot/cogs/audio/audio.py | 14 +++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 changelog.d/audio/3065.bugfix.rst diff --git a/changelog.d/audio/3065.bugfix.rst b/changelog.d/audio/3065.bugfix.rst new file mode 100644 index 000000000..cb4825bde --- /dev/null +++ b/changelog.d/audio/3065.bugfix.rst @@ -0,0 +1 @@ +Correctly reports the import error when an SQL dependency is missing. \ No newline at end of file diff --git a/redbot/cogs/audio/apis.py b/redbot/cogs/audio/apis.py index bd9f548d7..31f208da2 100644 --- a/redbot/cogs/audio/apis.py +++ b/redbot/cogs/audio/apis.py @@ -7,6 +7,7 @@ import logging import os import random import time +import traceback from collections import namedtuple from typing import Callable, Dict, List, Mapping, NoReturn, Optional, Tuple, Union @@ -15,11 +16,14 @@ try: from databases import Database HAS_SQL = True -except ModuleNotFoundError: + _ERROR = None +except ImportError as err: + _ERROR = "".join(traceback.format_exception_only(type(err), err)).strip() HAS_SQL = False - SQLError = ModuleNotFoundError + SQLError = err.__class__ Database = None + import aiohttp import discord import lavalink diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py index 420a726a6..e25cbda83 100644 --- a/redbot/cogs/audio/audio.py +++ b/redbot/cogs/audio/audio.py @@ -35,7 +35,7 @@ from redbot.core.utils.menus import ( ) from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate from . import dataclasses -from .apis import MusicCache, HAS_SQL +from .apis import MusicCache, HAS_SQL, _ERROR from .checks import can_have_caching from .converters import ComplexScopeParser, ScopeParser, get_lazy_converter, get_playlist_converter from .equalizer import Equalizer @@ -197,16 +197,16 @@ class Audio(commands.Cog): lavalink.register_event_listener(self.event_handler) if not HAS_SQL: error_message = ( - "Audio version: {version}\nThis version requires SQL to " + "Audio version: {version}\nThis version requires some SQL dependencies to " "access the caching features, " - "your Python install is missing the module sqlite3.\n\n" + "your Python install is missing some of them.\n\n" "For instructions on how to fix it Google " - "`ModuleNotFoundError: No module named '_sqlite3'`\n" - "You will need to reinstall " - "Python with SQL dependencies installed.\n\n" + f"`{_ERROR}`.\n" + "You will need to install the missing SQL dependency.\n\n" ).format(version=__version__) with contextlib.suppress(discord.HTTPException): - await self.bot.send_to_owners(error_message) + for page in pagify(error_message): + await self.bot.send_to_owners(page) log.critical(error_message) async def _migrate_config(self, from_version: int, to_version: int):