Skip to content

Commit 46fd076

Browse files
fix: clean error message (no traceback) and correct db path on schema mismatch (#1029)
* fix: show clean error (no traceback) and correct db path on schema mismatch [AI-assisted] - Catch SchemaVersionError at import time in cli.py; display via status_logger so the user sees a clean message instead of a raw Python traceback - Replace <db_path> placeholder with the actual database path in error messages * style: fix ruff import ordering in cli.py [AI-assisted] --------- Co-authored-by: florath-ai-assistant[bot] <Andreas.Florath@telekom.de>
1 parent 7eef545 commit 46fd076

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/aletheia_probe/cache/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def check_schema_compatibility(db_path: Path) -> bool:
104104
f"Database schema is from an old version of aletheia-probe (pre-1.0) "
105105
f"and cannot be used with this version (requires schema {SCHEMA_VERSION}).\n\n"
106106
f"Please delete the database and run sync again:\n"
107-
f" rm <db_path>\n"
107+
f" rm {db_path}\n"
108108
f" aletheia-probe sync"
109109
)
110110

@@ -113,7 +113,7 @@ def check_schema_compatibility(db_path: Path) -> bool:
113113
f"Database schema version ({current_version}) is too old "
114114
f"(requires {SCHEMA_VERSION}).\n\n"
115115
f"Please delete the database and run sync again:\n"
116-
f" rm <db_path>\n"
116+
f" rm {db_path}\n"
117117
f" aletheia-probe sync"
118118
)
119119

src/aletheia_probe/cli.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from . import __version__
1616
from .batch_assessor import BibtexBatchAssessor
1717
from .cache import AcronymCache, AssessmentCache, RetractionCache
18-
from .cache_sync import cache_sync_manager
18+
from .cache.schema import SchemaVersionError
1919
from .config import get_config_manager
2020
from .dispatcher import query_dispatcher
2121
from .enums import AssessmentType
@@ -25,6 +25,16 @@
2525
from .utils.dead_code import code_is_used
2626

2727

28+
# Import cache_sync last: instantiation at module level may raise SchemaVersionError
29+
# if the database schema is outdated. Caught here for a clean error message.
30+
_startup_error: SchemaVersionError | None = None
31+
try:
32+
from .cache_sync import cache_sync_manager # noqa: E402
33+
except SchemaVersionError as _e:
34+
_startup_error = _e
35+
cache_sync_manager = None # type: ignore[assignment]
36+
37+
2838
F = TypeVar("F", bound=Callable[..., Any])
2939

3040

@@ -148,6 +158,11 @@ def main(ctx: click.Context, config: Path | None) -> None:
148158
detail_logger, status_logger = setup_logging()
149159
detail_logger.debug("CLI initialized")
150160

161+
# Fail cleanly if the database schema was incompatible at startup
162+
if _startup_error is not None:
163+
status_logger.error(str(_startup_error))
164+
sys.exit(1)
165+
151166
# Initialize config manager with custom path if provided
152167
if config:
153168
detail_logger.debug(f"Using config file: {config}")

0 commit comments

Comments
 (0)