Commit 801234a9 authored by Glandos's avatar Glandos
Browse files

catch exceptions in a nicer way

parent 156962e9
...@@ -96,10 +96,10 @@ class Database(ABC): ...@@ -96,10 +96,10 @@ class Database(ABC):
self.close() self.close()
def close(self): def close(self):
if self.cursor is not None: if getattr(self, "cursor", None) is not None:
self.cursor.close() self.cursor.close()
self.cursor = None self.cursor = None
if self.connection is not None: if getattr(self, "connection", None) is not None:
self.connection.close() self.connection.close()
self.connection = None self.connection = None
...@@ -151,8 +151,9 @@ class Database(ABC): ...@@ -151,8 +151,9 @@ class Database(ABC):
class SQLite(Database): class SQLite(Database):
def __init__(self, filename: str, source: SQLite = None): def __init__(self, filename: str, source: SQLite = None):
self.source = None
if source is not None and not isinstance(source, SQLite): if source is not None and not isinstance(source, SQLite):
raise NotImplemented("SQLite target can only use SQLite source") raise ValueError("SQLite target can only use SQLite source")
super().__init__(filename, source) super().__init__(filename, source)
# For type hints # For type hints
self.source = source self.source = source
...@@ -468,8 +469,12 @@ class PostgreSQL(Database): ...@@ -468,8 +469,12 @@ class PostgreSQL(Database):
@click.argument("merged-db") @click.argument("merged-db")
def main(main_db, merged_db, fast): def main(main_db, merged_db, fast):
click.echo(f"Merging {merged_db} into {main_db}") click.echo(f"Merging {merged_db} into {main_db}")
source = Database.from_dsn(merged_db) try:
target = Database.from_dsn(main_db, source) source = Database.from_dsn(merged_db)
target = Database.from_dsn(main_db, source)
except Exception as e:
raise click.ClickException(e)
return
target.set_options({"fast": fast}) target.set_options({"fast": fast})
click.echo("-> Gathering source database statistics: ", nl=False) click.echo("-> Gathering source database statistics: ", nl=False)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment