update error handling for not registered browser

This commit is contained in:
qwjyh 2025-01-08 14:30:05 +09:00
parent 7486098a11
commit eb98ce47cb

View file

@ -188,7 +188,7 @@ def get_db_type(cur: sqlite3.Cursor) -> Literal["firefox", "chromium"]:
return db_type 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( res = root_cur.execute(
""" """
SELECT SELECT
@ -202,7 +202,10 @@ def get_browser_info(root_cur: sqlite3.Cursor, name: str) -> tuple[int, int, str
""", """,
(name,), (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) 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 root_con: sqlite3.Connection, root_cur: sqlite3.Cursor, args: argparse.Namespace
): ):
print("Add history to root db") 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"{browser_id=}, {visits_time_max=}")
logging.info(f"Source: {database_path}") logging.info(f"Source: {database_path}")