From 204b995e6c4a916e875ebfdc86cfe1cd83933ad3 Mon Sep 17 00:00:00 2001 From: "Mohammad Mahdi \"Mamad\" Afshar" <22727144+reloadlife@users.noreply.github.com> Date: Sat, 19 Oct 2024 19:25:38 +0330 Subject: [PATCH 1/2] added a try/catch statement to prevent panel from crashing #432 --- src/dashboard.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 3edba2e..66aa969 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -403,9 +403,13 @@ class PeerShareLinks: # print(self.Links) def __getSharedLinks(self): self.Links.clear() - allLinks = sqlSelect("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall() - for link in allLinks: - self.Links.append(PeerShareLink(*link)) + try: + allLinks = sqlSelect("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall() + for link in allLinks: + self.Links.append(PeerShareLink(*link)) + # temo fix for https://github.com/donaldzou/WGDashboard/issues/432 + except sqlite3.DatabaseError as e: + print(f"Database error occurred: {e}") def getLink(self, Configuration: str, Peer: str) -> list[PeerShareLink]: self.__getSharedLinks() From bb0aba586b01e470c90ac85797d6cfc8efc39d40 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sun, 20 Oct 2024 16:05:32 +0800 Subject: [PATCH 2/2] Update dashboard.py Instead of catching one sql statement error, I moved the catch statement to `sqlSelect` to prevent all database error --- src/dashboard.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 66aa969..1cfbf71 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -403,13 +403,9 @@ class PeerShareLinks: # print(self.Links) def __getSharedLinks(self): self.Links.clear() - try: - allLinks = sqlSelect("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall() - for link in allLinks: - self.Links.append(PeerShareLink(*link)) - # temo fix for https://github.com/donaldzou/WGDashboard/issues/432 - except sqlite3.DatabaseError as e: - print(f"Database error occurred: {e}") + allLinks = sqlSelect("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall() + for link in allLinks: + self.Links.append(PeerShareLink(*link)) def getLink(self, Configuration: str, Peer: str) -> list[PeerShareLink]: self.__getSharedLinks() @@ -1427,8 +1423,13 @@ cursor = sqldb.cursor() def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: with sqldb: - cursor = sqldb.cursor() - return cursor.execute(statement, paramters) + try: + cursor = sqldb.cursor() + return cursor.execute(statement, paramters) + # temo fix for https://github.com/donaldzou/WGDashboard/issues/432 + except sqlite3.DatabaseError as e: + print(f"Database error occurred: {e}") + return [] def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor: with sqldb: