From 95e38e71377a3553c8e7b13cfb80a2f294e44a7e Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Fri, 21 Aug 2026 11:45:07 +0300 Subject: [PATCH] Print configuration mismatches instead of raising them A database whose stored embedder disagrees with the configuration raised ConfigMismatchError through Typer, so the operator got a traceback wrapped around the one message that says what to run, while every sibling failure exits with its message. It joins the errors the CLI reports. Imported inside cli() rather than at module scope: the settings module pulls in lancedb, and importing the CLI must not pay for it. --- CHANGELOG.md | 1 + haiku_rag_slim/haiku/rag/cli.py | 5 +++++ tests/test_cli.py | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260a8f0c..996d04d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - `doctor`'s docling-serve probe sends `X-Api-Key`, so an instance requiring a key is reported reachable rather than unreachable. - The picture-description request to the public OpenAI endpoint sends `OPENAI_API_KEY`; it carried no authorization header. +- `haiku-rag` prints the message and exits when the configured embedder does not match the database, instead of raising a traceback. ## [0.77.0] - 2026-08-21 diff --git a/haiku_rag_slim/haiku/rag/cli.py b/haiku_rag_slim/haiku/rag/cli.py index 69c1bc5a..b6d3539c 100644 --- a/haiku_rag_slim/haiku/rag/cli.py +++ b/haiku_rag_slim/haiku/rag/cli.py @@ -42,10 +42,15 @@ _cli = typer.Typer( def cli(): + # Imported here rather than at module scope: the settings module pulls in + # lancedb, and the CLI's startup must not pay for it. + from haiku.rag.store.repositories.settings import ConfigMismatchError + try: _cli() except ( AmbiguousDatabaseError, + ConfigMismatchError, MigrationRequiredError, ReadOnlyError, SourceUnavailableError, diff --git a/tests/test_cli.py b/tests/test_cli.py index 13382813..17c1df41 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -328,6 +328,22 @@ class TestResolvingTheDatabasePath: resolve_db_path(Path("/data/other.lancedb")) +class TestCliConfigMismatchError: + def test_a_config_mismatch_exits_with_its_remedy(self): + """The message says which database and what to run, so it is worth more + than a traceback.""" + from haiku.rag.store.repositories.settings import ConfigMismatchError + + with patch("haiku.rag.cli._cli") as mock_cli: + mock_cli.side_effect = ConfigMismatchError( + "database 'nemotron': vector dimension 2048 -> 2560" + ) + + with pytest.raises(SystemExit) as exc_info: + cli_wrapper() + assert exc_info.value.code == 1 + + class TestCliMigrationError: def test_catches_migration_required_error(self): with patch("haiku.rag.cli._cli") as mock_cli: