Skip to content

Commit

Permalink
Nicer error messages for dsn syntax errors (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
blogh authored Mar 17, 2021
1 parent 95faf1e commit aeed63e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pgactivity/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import psutil
import psycopg2
import psycopg2.extras
from psycopg2.errors import InterfaceError, InvalidPassword, OperationalError
from psycopg2.errors import InterfaceError, InvalidPassword, OperationalError, ProgrammingError
from psycopg2.extensions import connection

from . import queries
Expand Down Expand Up @@ -395,6 +395,11 @@ def pg_connect(
raise SystemExit("pg_activity: FATAL: %s" % clean_str(msg))
else:
raise Exception("Could not connect to PostgreSQL")
except ProgrammingError as err:
errmsg = str(err).strip()
if errmsg.startswith("invalid dsn"):
raise SystemExit(f"ERROR: {errmsg}\nPlease refer to the 'Connection Control Functions' section of the PostgreSQL documentation")
raise
else:
break
return data

0 comments on commit aeed63e

Please sign in to comment.