handle exceptions
This commit is contained in:
parent
3d3fb25d78
commit
678566ccc2
1 changed files with 12 additions and 2 deletions
|
@ -60,7 +60,12 @@ class find_duplicate_files:
|
|||
|
||||
def _check_file_cache(self, file):
|
||||
file_sql = file.replace("'", "\'")
|
||||
result = self.cur.execute(f"SELECT hash FROM files WHERE file = '{file_sql}'")
|
||||
query = f"SELECT hash FROM files WHERE file = '{file_sql}'"
|
||||
try:
|
||||
result = self.cur.execute(query)
|
||||
except Exception as error:
|
||||
self._log.error("Error executing query '{query}'. {error}")
|
||||
sys.exit(2)
|
||||
row = result.fetchone()
|
||||
if row and len(row) > 0:
|
||||
return row[0]
|
||||
|
@ -69,7 +74,12 @@ class find_duplicate_files:
|
|||
|
||||
def _cache_file(self, file, hash):
|
||||
file_sql = file.replace("'", "\'")
|
||||
result = self.cur.execute(f"INSERT INTO files (hash, file) VALUES ('{file_sql}', '{hash}')")
|
||||
query = f"INSERT INTO files (hash, file) VALUES ('{file_sql}', '{hash}')"
|
||||
try:
|
||||
result = self.cur.execute(query)
|
||||
except Exception as error:
|
||||
self._log.error("Error executing query '{query}'. {error}")
|
||||
sys.exit(3)
|
||||
self.cache_db.commit()
|
||||
return result
|
||||
|
||||
|
|
Loading…
Reference in a new issue