Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: replace bare except clauses in database module (#2006)

LearningCircuit2462ab3f8bf7
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 5ac3358dc8..ced7256d3d 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -108,8 +108,10 @@ class DatabaseManager:
# Clean up test file
try:
os_module.unlink(tmp_path)
- except:
- pass
+ except OSError as e:
+ logger.debug(
+ f"Failed to clean up temp file {tmp_path}: {e}"
+ )
except ImportError:
import os
@@ -170,16 +172,16 @@ class DatabaseManager:
for pragma in pragmas:
try:
connection.execute(pragma)
- except Exception:
- pass
+ except Exception as e:
+ logger.debug(f"Could not apply pragma '{pragma}': {e}")
else:
# Regular SQLite pragma
try:
connection.execute(
"PRAGMA mmap_size = 268435456"
) # 256MB memory mapping
- except Exception:
- pass
+ except Exception as e:
+ logger.debug(f"Could not apply mmap_size pragma: {e}")
def create_user_database(self, username: str, password: str) -> Engine:
"""Create a new encrypted database for a user."""
@@ -642,15 +644,17 @@ class DatabaseManager:
# Engine is valid, create session from it
Session = sessionmaker(bind=engine)
return Session()
- except Exception:
+ except Exception as e:
# Engine is stale, remove it and create new one
logger.debug(
- f"Stale thread engine for {engine_key}, recreating"
+ f"Stale thread engine for {engine_key}, recreating: {e}"
)
try:
engine.dispose()
- except Exception:
- pass
+ except Exception as dispose_error:
+ logger.debug(
+ f"Error disposing stale engine: {dispose_error}"
+ )
del self._thread_engines[engine_key]
# Create a thread-local engine
diff --git a/tests/database/test_encrypted_db_extended.py b/tests/database/test_encrypted_db_extended.py
index 49e1f4a198..7382c4dbe3 100644
--- a/tests/database/test_encrypted_db_extended.py
+++ b/tests/database/test_encrypted_db_extended.py
@@ -413,3 +413,48 @@ class TestDatabaseEncryption:
key_matches = correct_key == provided_key
assert not key_matches
+
+
+class TestEncryptedDbExceptionLogging:
+ """Tests for improved exception logging in encrypted_db (PR #2006).
+
+ PR #2006 adds logger.debug() to exception handlers for:
+ - Temp file cleanup (OSError)
+ - Pragma application failures
+ - Stale engine disposal
+ """
+
+ def test_os_error_is_subclass_hierarchy(self):
+ """OSError catches FileNotFoundError and PermissionError."""
+ assert issubclass(FileNotFoundError, OSError)
+ assert issubclass(PermissionError, OSError)
+
+ def test_pragma_failure_caught_by_exception(self):
+ """Pragma execution errors are caught by except Exception."""
+ errors = []
+ pragmas = ["PRAGMA invalid_pragma = 1", "PRAGMA valid = 1"]
+
+ for pragma in pragmas:
+ try:
+ if "invalid" in pragma:
+ raise Exception(f"Could not apply pragma '{pragma}'")
+ except Exception as e:
+ errors.append(str(e))
+
+ assert len(errors) == 1
+ assert "invalid" in errors[0]
+
+ def test_engine_dispose_error_caught(self):
+ """Engine disposal errors are caught and logged."""
+ from unittest.mock import Mock
+
+ mock_engine = Mock()
+ mock_engine.dispose.side_effect = Exception("Connection pool error")
+
+ caught = False
+ try:
+ mock_engine.dispose()
+ except Exception:
+ caught = True
+
+ assert caught