aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-05-03 22:14:29 +0200
committerWolfgang Müller2021-05-03 22:30:15 +0200
commita096cc81cfa65a166127a3a7e0942c277fbb66b8 (patch)
treeaf66dc73649c19d1700baf694bf8e83e20627b6c
parent299aa62f5d22a5942e0b3a61eaa6cc0353770b0e (diff)
downloadquarg-a096cc81cfa65a166127a3a7e0942c277fbb66b8.tar.gz
main: Handle SQLAlchemy errors more nicely
Instead of giving the user a screen full of backtraces, catch any errors SQLAlchemy can run into when preparing or executing the query and report only the error message to the user. We include the print loop in the try/except block because an upcoming commit will add a handler for KeyboardInterrupt.
-rw-r--r--quarg/main.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/quarg/main.py b/quarg/main.py
index ce72310..9532ba7 100644
--- a/quarg/main.py
+++ b/quarg/main.py
@@ -4,13 +4,13 @@ import os
import sys
from timeit import default_timer as timer
-from sqlalchemy import create_engine
+from sqlalchemy import create_engine, exc
from sqlalchemy.orm import sessionmaker
import quarg.actions as actions
import quarg.database.filters as filters
+import quarg.quassel.formatter as formatter
from quarg.database.tables import Backlog, Buffer, Network, QuasselUser, Sender
-from quarg.quassel.formatter import format_from
from quarg.utils import errx
# pylint: disable=line-too-long
@@ -136,11 +136,14 @@ def main():
if not predicates:
errx('Nothing to match.')
- query = prepare_query(session, predicates, args)
- rows, time = time_query(query)
+ try:
+ query = prepare_query(session, predicates, args)
+ rows, time = time_query(query)
- for row in rows:
- print(format_from(row))
+ for row in rows:
+ print(formatter.format_from(row))
+ except exc.SQLAlchemyError as err:
+ errx(err)
print(f'Query returned {len(rows)} lines in {time:.4f} seconds.', file=sys.stderr)