Name a remedy the command being used has
`haiku-ingester` reached the client's refusal, which names `sources=[name]`, a Python argument no CLI user can pass. It refuses a configured set itself, with `--db PATH` and the one-ingester-per-database layout. `haiku-rag`'s own refusal now says where each option goes: `--db-name` is global and precedes the command, `--db` follows it.
This commit is contained in:
parent
5ecffdedf2
commit
95c02addd7
4 changed files with 33 additions and 3 deletions
|
|
@ -105,8 +105,8 @@ def resolve_scope(
|
||||||
if scope.covers_multiple and not covers_set:
|
if scope.covers_multiple and not covers_set:
|
||||||
raise AmbiguousDatabaseError(
|
raise AmbiguousDatabaseError(
|
||||||
f"lancedb.databases names {', '.join(sorted(scope.names))}; this "
|
f"lancedb.databases names {', '.join(sorted(scope.names))}; this "
|
||||||
"command works on a single database: pass --db-name NAME, or "
|
"command works on a single database: pass --db-name NAME before "
|
||||||
"--db PATH."
|
"the command, or --db PATH after it"
|
||||||
)
|
)
|
||||||
return scope
|
return scope
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,19 @@ class IngesterApp:
|
||||||
|
|
||||||
def __init__(self, *, config: AppConfig, db_path: Path | None = None):
|
def __init__(self, *, config: AppConfig, db_path: Path | None = None):
|
||||||
from haiku.rag.client.scope import DatabaseScope
|
from haiku.rag.client.scope import DatabaseScope
|
||||||
|
from haiku.rag.store.exceptions import AmbiguousDatabaseError
|
||||||
|
|
||||||
self._config = config
|
self._config = config
|
||||||
# `--db` names the database directly, and nothing stands in for it: a
|
# `--db` names the database directly, and nothing stands in for it: a
|
||||||
# manufactured default would override a configured `lancedb.uri`.
|
# manufactured default would override a configured `lancedb.uri`.
|
||||||
self._scope = DatabaseScope.resolve(config, database_path=db_path)
|
self._scope = DatabaseScope.resolve(config, database_path=db_path)
|
||||||
|
if self._scope.covers_multiple:
|
||||||
|
raise AmbiguousDatabaseError(
|
||||||
|
"haiku-ingester writes one database, and lancedb.databases "
|
||||||
|
f"names {', '.join(self._scope.names)}; select one with "
|
||||||
|
"--db PATH, or give each database its own ingester with a "
|
||||||
|
"configuration naming a single one"
|
||||||
|
)
|
||||||
self._engine: AsyncEngine | None = None
|
self._engine: AsyncEngine | None = None
|
||||||
self._jobs: JobRepo | None = None
|
self._jobs: JobRepo | None = None
|
||||||
self._sync: SyncStateRepo | None = None
|
self._sync: SyncStateRepo | None = None
|
||||||
|
|
|
||||||
|
|
@ -525,6 +525,23 @@ class TestPlacingTheIngesterDatabase:
|
||||||
assert scope.names == ("docs",)
|
assert scope.names == ("docs",)
|
||||||
assert not scope.covers_multiple
|
assert not scope.covers_multiple
|
||||||
|
|
||||||
|
def test_a_set_is_refused_with_a_remedy_this_command_has(self, tmp_path):
|
||||||
|
"""The client would name `sources=[name]`, a Python argument no CLI user
|
||||||
|
can pass."""
|
||||||
|
from haiku.rag.store.exceptions import AmbiguousDatabaseError
|
||||||
|
|
||||||
|
config = AppConfig(
|
||||||
|
lancedb=LanceDBConfig(
|
||||||
|
databases={"a": str(tmp_path / "a"), "b": str(tmp_path / "b")}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(AmbiguousDatabaseError) as raised:
|
||||||
|
self._app(config)
|
||||||
|
|
||||||
|
assert "--db PATH" in str(raised.value)
|
||||||
|
assert "sources=" not in str(raised.value)
|
||||||
|
|
||||||
def test_several_configured_databases_exit_cleanly(self, tmp_path, monkeypatch):
|
def test_several_configured_databases_exit_cleanly(self, tmp_path, monkeypatch):
|
||||||
"""No selector names one of a set, so the CLI reports it rather than
|
"""No selector names one of a set, so the CLI reports it rather than
|
||||||
printing a traceback."""
|
printing a traceback."""
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,14 @@ class TestOneDatabaseCommands:
|
||||||
def test_a_configured_set_refuses_a_one_database_command(self, monkeypatch):
|
def test_a_configured_set_refuses_a_one_database_command(self, monkeypatch):
|
||||||
self._install(monkeypatch, alpha="/db/a.lancedb", beta="/db/b.lancedb")
|
self._install(monkeypatch, alpha="/db/a.lancedb", beta="/db/b.lancedb")
|
||||||
|
|
||||||
with pytest.raises(AmbiguousDatabaseError, match="alpha, beta"):
|
with pytest.raises(AmbiguousDatabaseError, match="alpha, beta") as raised:
|
||||||
resolve_scope(None)
|
resolve_scope(None)
|
||||||
|
|
||||||
|
# `--db-name` is global and `--db` is per-command, so the remedy says
|
||||||
|
# where each one goes.
|
||||||
|
assert "--db-name NAME before the command" in str(raised.value)
|
||||||
|
assert "--db PATH after it" in str(raised.value)
|
||||||
|
|
||||||
def test_the_refusal_names_the_databases_and_not_their_locations(self, monkeypatch):
|
def test_the_refusal_names_the_databases_and_not_their_locations(self, monkeypatch):
|
||||||
"""A location in an error message travels into logs and terminals; the
|
"""A location in an error message travels into logs and terminals; the
|
||||||
names exist so it does not have to."""
|
names exist so it does not have to."""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue