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:
parent
5e81054a1e
commit
dafc15978e
3 changed files with 28 additions and 7 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue