From eb98ce47cbbf36389df5899b98cc975f0a4f61ed Mon Sep 17 00:00:00 2001 From: qwjyh Date: Wed, 8 Jan 2025 14:30:05 +0900 Subject: [PATCH] update error handling for not registered browser --- src/browser_history_merger/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/browser_history_merger/__init__.py b/src/browser_history_merger/__init__.py index a44a76e..493b9fe 100644 --- a/src/browser_history_merger/__init__.py +++ b/src/browser_history_merger/__init__.py @@ -188,7 +188,7 @@ def get_db_type(cur: sqlite3.Cursor) -> Literal["firefox", "chromium"]: return db_type -def get_browser_info(root_cur: sqlite3.Cursor, name: str) -> tuple[int, int, str]: +def get_browser_info(root_cur: sqlite3.Cursor, name: str) -> tuple[int, int, str] | None: res = root_cur.execute( """ SELECT @@ -202,7 +202,10 @@ def get_browser_info(root_cur: sqlite3.Cursor, name: str) -> tuple[int, int, str """, (name,), ) - browser_id, visits_time_max, database_path = res.fetchone() + res_one = res.fetchone() + if res_one is None: + return None + browser_id, visits_time_max, database_path = res_one return (browser_id, visits_time_max, database_path) @@ -250,7 +253,13 @@ def add_db( root_con: sqlite3.Connection, root_cur: sqlite3.Cursor, args: argparse.Namespace ): print("Add history to root db") - browser_id, visits_time_max, database_path = get_browser_info(root_cur, args.name) + browser_info = get_browser_info(root_cur, args.name) + if browser_info is None: + print(f"browser {args.name} is not registered to the database") + logging.debug("Cleaning up (closing db connection)") + root_con.close() + exit(1) + browser_id, visits_time_max, database_path = browser_info logging.info(f"{browser_id=}, {visits_time_max=}") logging.info(f"Source: {database_path}")