From 223015a1facba4c2bfa1873235998cd845f0715e Mon Sep 17 00:00:00 2001 From: Tom Caruso Date: Fri, 31 Jul 2020 13:25:06 -0400 Subject: More explicit error message when DSN alias is not found (#1198) * add a specific error message when DSN with provided alias is not found * update changelog & authors file --- changelog.rst | 1 + pgcli/main.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/changelog.rst b/changelog.rst index ca968dce..2c5e7ca7 100644 --- a/changelog.rst +++ b/changelog.rst @@ -17,6 +17,7 @@ Bug fixes: * Minor typo fixes in `pgclirc`. (Thanks: `anthonydb`_) * Fix for list index out of range when executing commands from a file (#1193). (Thanks: `Irina Truong`_) * Move from `humanize` to `pendulum` for displaying query durations (#1015) +* More explicit error message when connecting using DSN alias and it is not found. 3.0.0 ===== diff --git a/pgcli/main.py b/pgcli/main.py index cb41b2b1..a2821368 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -1284,7 +1284,15 @@ def cli( try: cfg = load_config(pgclirc, config_full_path) dsn_config = cfg["alias_dsn"][dsn] - except: + except KeyError: + click.secho( + f"Could not find a DSN with alias {dsn}. " + 'Please check the "[alias_dsn]" section in pgclirc.', + err=True, + fg="red", + ) + exit(1) + except Exception: click.secho( "Invalid DSNs found in the config file. " 'Please check the "[alias_dsn]" section in pgclirc.', -- cgit v1.2.3