8000 fix(store): say which setting to fix when SurrealDB refuses the password by adeelahmad · Pull Request #254 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions fastapi_backend/app/domain/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,16 @@ def __init__(self, cfg, pool_size=None):
self._pool.put(c)
except Exception as e: # noqa: BLE001
self.close()
hint = (
" If another process has this embedded database open, stop it or point both at a SurrealDB server (SURREAL_URL=ws://...)."
if self.embedded
else ""
)
if self.embedded:
hint = " If another process has this embedded database open, stop it or point both at a SurrealDB server (SURREAL_URL=ws://...)."
elif "authentication" in str(e).lower():
# the server keeps the root user it was first started with: a later SURREAL_PASS doesn't change it
hint = (
" SURREAL_USER/SURREAL_PASS don't match the user this database was created with."
" Set them back to the values it was first started with (see .env), then restart."
)
else:
hint = ""
raise SystemExit(f"cannot open SurrealDB at {url}: {e}.{hint}") from None

def _open(self):
Expand Down
11 changes: 11 additions & 0 deletions fastapi_backend/tests/domain/test_store_reconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ def down():
assert d._all == [dead]
monkeypatch.setattr(d, "_open", lambda: fresh)
assert d.values("SELECT 1") == [7]


def test_a_wrong_server_password_says_which_setting_to_fix(monkeypatch):
def refused(self):
raise Exception("There was a problem with authentication")

monkeypatch.setattr(store.DB, "_open", refused)
cfg = {"data_dir": "/tmp", "database": {"url": "ws://test", "namespace": "n", "database": "d"}}
monkeypatch.delenv("SURREAL_URL", raising=False)
with pytest.raises(SystemExit, match="SURREAL_PASS don't match the user this database was created with"):
store.DB(cfg)
Loading
0