From dafc15978e7c391681acb4544411281b7f613a37 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Fri, 28 Aug 2026 09:59:37 +0300 Subject: [PATCH] Translate every database-opening failure in haiku-ingester `ConfigMismatchError` and `SourceUnavailableError` escaped the entry point as tracebacks rather than a message and exit code 1. The entry-point test is parametrized over the translated types, so the two CLIs' lists cannot drift apart silently again. --- CHANGELOG.md | 2 +- haiku_rag_slim/haiku/rag/ingester/cli.py | 4 ++++ tests/ingester/test_cli.py | 29 +++++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fa0175d..b10e8b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ lists the selected separately, instead of mounting a checkbox per document. Selection is by document ID. - `haiku-rag list` prints only the fields a document has. -- `haiku-rag` prints the message and exits when the configured embedder does not match the database, instead of raising a traceback. +- `haiku-rag` and `haiku-ingester` print the message and exit when the configured embedder does not match the database, instead of raising a traceback. - Capabilities created without a client honor `lancedb.uri`. - A `lancedb.uri` without a scheme is treated as a local path. `--db PATH` overrides it. diff --git a/haiku_rag_slim/haiku/rag/ingester/cli.py b/haiku_rag_slim/haiku/rag/ingester/cli.py index ed359897..4a1684ca 100644 --- a/haiku_rag_slim/haiku/rag/ingester/cli.py +++ b/haiku_rag_slim/haiku/rag/ingester/cli.py @@ -34,8 +34,10 @@ from haiku.rag.ingester.queue.migrations import open_queue # noqa: E402 from haiku.rag.logging import configure_cli_logging # noqa: E402 from haiku.rag.store.exceptions import ( # noqa: E402 AmbiguousDatabaseError, + ConfigMismatchError, MigrationRequiredError, ReadOnlyError, + SourceUnavailableError, UnknownDatabaseError, ) @@ -74,8 +76,10 @@ def cli() -> None: _cli() except ( AmbiguousDatabaseError, + ConfigMismatchError, MigrationRequiredError, ReadOnlyError, + SourceUnavailableError, UnknownDatabaseError, ) as e: typer.echo(f"Error: {e}", err=True) diff --git a/tests/ingester/test_cli.py b/tests/ingester/test_cli.py index 395af6ff..aa5c1b01 100644 --- a/tests/ingester/test_cli.py +++ b/tests/ingester/test_cli.py @@ -24,6 +24,14 @@ from haiku.rag.ingester.cli import _cli as cli from haiku.rag.ingester.cli import _resolve_queue_config from haiku.rag.ingester.cli import cli as ingester_cli from haiku.rag.ingester.queue.models import JobOp +from haiku.rag.store.exceptions import ( + AmbiguousDatabaseError, + ConfigMismatchError, + MigrationRequiredError, + ReadOnlyError, + SourceUnavailableError, + UnknownDatabaseError, +) runner = CliRunner() @@ -469,20 +477,29 @@ def test_cli_entry_point(monkeypatch): mock_cli.assert_called_once() -def test_cli_entry_point_exits_on_migration_error(monkeypatch): +@pytest.mark.parametrize( + "error", + [ + AmbiguousDatabaseError("names a set"), + ConfigMismatchError("embedder drifted"), + MigrationRequiredError("need migration"), + ReadOnlyError("read-only"), + SourceUnavailableError("papers would not open"), + UnknownDatabaseError("no such database"), + ], + ids=lambda e: type(e).__name__, +) +def test_cli_entry_point_exits_on_store_state_errors(monkeypatch, capsys, error): from haiku.rag.ingester.cli import cli as cli_entry - from haiku.rag.store.exceptions import MigrationRequiredError - monkeypatch.setattr( - "haiku.rag.ingester.cli._cli", - MagicMock(side_effect=MigrationRequiredError("need migration")), - ) + monkeypatch.setattr("haiku.rag.ingester.cli._cli", MagicMock(side_effect=error)) monkeypatch.setattr("haiku.rag.ingester.cli.configure_cli_logging", lambda: None) monkeypatch.setattr("haiku.rag.telemetry.configure", lambda **_: None) with pytest.raises(SystemExit) as exc_info: cli_entry() assert exc_info.value.code == 1 + assert f"Error: {error}" in capsys.readouterr().err class TestPlacingTheIngesterDatabase: