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.
This commit is contained in:
Yiorgis Gozadinos 2026-08-28 09:59:37 +03:00
parent 5e81054a1e
commit dafc15978e
No known key found for this signature in database
3 changed files with 28 additions and 7 deletions

View file

@ -27,7 +27,7 @@
lists the selected separately, instead of mounting a checkbox per document. lists the selected separately, instead of mounting a checkbox per document.
Selection is by document ID. Selection is by document ID.
- `haiku-rag list` prints only the fields a document has. - `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`. - Capabilities created without a client honor `lancedb.uri`.
- A `lancedb.uri` without a scheme is treated as a local path. `--db PATH` - A `lancedb.uri` without a scheme is treated as a local path. `--db PATH`
overrides it. overrides it.

View file

@ -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.logging import configure_cli_logging # noqa: E402
from haiku.rag.store.exceptions import ( # noqa: E402 from haiku.rag.store.exceptions import ( # noqa: E402
AmbiguousDatabaseError, AmbiguousDatabaseError,
ConfigMismatchError,
MigrationRequiredError, MigrationRequiredError,
ReadOnlyError, ReadOnlyError,
SourceUnavailableError,
UnknownDatabaseError, UnknownDatabaseError,
) )
@ -74,8 +76,10 @@ def cli() -> None:
_cli() _cli()
except ( except (
AmbiguousDatabaseError, AmbiguousDatabaseError,
ConfigMismatchError,
MigrationRequiredError, MigrationRequiredError,
ReadOnlyError, ReadOnlyError,
SourceUnavailableError,
UnknownDatabaseError, UnknownDatabaseError,
) as e: ) as e:
typer.echo(f"Error: {e}", err=True) typer.echo(f"Error: {e}", err=True)

View file

@ -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 _resolve_queue_config
from haiku.rag.ingester.cli import cli as ingester_cli from haiku.rag.ingester.cli import cli as ingester_cli
from haiku.rag.ingester.queue.models import JobOp from haiku.rag.ingester.queue.models import JobOp
from haiku.rag.store.exceptions import (
AmbiguousDatabaseError,
ConfigMismatchError,
MigrationRequiredError,
ReadOnlyError,
SourceUnavailableError,
UnknownDatabaseError,
)
runner = CliRunner() runner = CliRunner()
@ -469,20 +477,29 @@ def test_cli_entry_point(monkeypatch):
mock_cli.assert_called_once() mock_cli.assert_called_once()
def test_cli_entry_point_exits_on_migration_error(monkeypatch): @pytest.mark.parametrize(
from haiku.rag.ingester.cli import cli as cli_entry "error",
from haiku.rag.store.exceptions import MigrationRequiredError [
AmbiguousDatabaseError("names a set"),
monkeypatch.setattr( ConfigMismatchError("embedder drifted"),
"haiku.rag.ingester.cli._cli", MigrationRequiredError("need migration"),
MagicMock(side_effect=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
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.ingester.cli.configure_cli_logging", lambda: None)
monkeypatch.setattr("haiku.rag.telemetry.configure", lambda **_: None) monkeypatch.setattr("haiku.rag.telemetry.configure", lambda **_: None)
with pytest.raises(SystemExit) as exc_info: with pytest.raises(SystemExit) as exc_info:
cli_entry() cli_entry()
assert exc_info.value.code == 1 assert exc_info.value.code == 1
assert f"Error: {error}" in capsys.readouterr().err
class TestPlacingTheIngesterDatabase: class TestPlacingTheIngesterDatabase: