From 80628a28a7db299bdc7b09827503571c74542304 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Sat, 28 Sep 2019 23:22:45 +0200 Subject: [PATCH] [Core] Give friendly error when provided instance name doesn't exist. (#2969) * Update data_manager.py * Towncrier entry --- changelog.d/2968.bugfix.rst | 1 + redbot/core/data_manager.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelog.d/2968.bugfix.rst diff --git a/changelog.d/2968.bugfix.rst b/changelog.d/2968.bugfix.rst new file mode 100644 index 000000000..5f6065eb2 --- /dev/null +++ b/changelog.d/2968.bugfix.rst @@ -0,0 +1 @@ +Give friendly error when provided instance name doesn't exist. diff --git a/redbot/core/data_manager.py b/redbot/core/data_manager.py index be1632809..72394ac43 100644 --- a/redbot/core/data_manager.py +++ b/redbot/core/data_manager.py @@ -91,14 +91,20 @@ def load_basic_configuration(instance_name_: str): try: with config_file.open(encoding="utf-8") as fs: config = json.load(fs) - except (FileNotFoundError, KeyError): + except FileNotFoundError: print( "You need to configure the bot instance using `redbot-setup`" " prior to running the bot." ) sys.exit(1) - else: + try: basic_config = config[instance_name] + except KeyError: + print( + "Instance with this name doesn't exist." + " You can create new instance using `redbot-setup` prior to running the bot." + ) + sys.exit(1) def _base_data_path() -> Path: