From 3a0278d7e4d7af2ad3e5f7a36b1e7ebeb2f611dd Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Fri, 9 Oct 2026 18:40:53 +0000 Subject: [PATCH] fix(store): say which setting to fix when SurrealDB refuses the password Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012wcFmyYcWVbxxKpGsR652k --- fastapi_backend/app/domain/store.py | 15 ++++++++++----- .../tests/domain/test_store_reconnect.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/fastapi_backend/app/domain/store.py b/fastapi_backend/app/domain/store.py index a426aff35..b02f58961 100644 --- a/fastapi_backend/app/domain/store.py +++ b/fastapi_backend/app/domain/store.py @@ -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): diff --git a/fastapi_backend/tests/domain/test_store_reconnect.py b/fastapi_backend/tests/domain/test_store_reconnect.py index c60181f53..ae260c0a0 100644 --- a/fastapi_backend/tests/domain/test_store_reconnect.py +++ b/fastapi_backend/tests/domain/test_store_reconnect.py @@ -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)