Skip to content

fix(db): raise a dedicated error when the SQLCipher connection fails - #258

Open
bfs2021 wants to merge 2 commits into
smswithoutborders:stagingfrom
bfs2021:fix/db-connect-error-type
Open

bfs2021 wants to merge 2 commits into
smswithoutborders:stagingfrom
bfs2021:fix/db-connect-error-type

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 20, 2026

Copy link
Copy Markdown

Problem

When the SQLCipher key is wrong or the database file is corrupted, the connection check in publisher/db/__init__.py raises a plain ValueError. Callers that catch ValueError around key lookups then report this connection failure to clients: GET /v1/server-keys/{key_id} answers 404 with "Wrong key, or the database file is corrupted.", and the gRPC v3 interceptor rejects the request with the same message. Fixes #255

Root cause

_make_sqlcipher3_creator's connect() raises ValueError on a failed sqlite_master integrity check. publisher/api/rest/v1/server_keys.py and publisher/api/grpc/interceptors.py both use broad except ValueError around key lookups (for genuinely invalid key IDs), so the connection error is indistinguishable from a bad key ID and leaks to clients.

Fix

Add DatabaseConnectionError (a plain Exception subclass, deliberately not a ValueError) in publisher/db/__init__.py and raise it from the SQLCipher creator instead. The two handlers keep catching ValueError for real key-lookup problems; a failed connection now propagates and surfaces as a generic internal error in both the REST route and the gRPC interceptor. No handler changes needed.

Testing

  • New regression test tests/db/test_engine.py::test_failing_sqlcipher_integrity_check_is_not_a_value_error: fails before the fix (ValueError raised), passes after.
  • Locally verified on Windows with Python 3.12: the new test passes; the rest of tests/db/test_engine.py plus the API/db suites need sqlcipher3 (Linux-only wheels) and the Rust-generated payload specs, so the full suite runs in CI.
  • git diff is +43/-1 across two files.

PromiseFru and others added 2 commits October 29, 2026 19:40
A wrong SQLCipher key made the connection creator raise a plain
ValueError. Handlers in the server-keys route and the gRPC interceptor
catch ValueError around key lookups, so that connection failure was
reported to clients (404 / rejected request) instead of surfacing as an
internal error. Raise DatabaseConnectionError, which is not a
ValueError, so those handlers no longer leak it.
@github-actions github-actions Bot added the not-following-guidelines The PR doesn't follow CONTRIBUTING.md yet label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Thank you, the base branch and tests now follow the contribution guide.

@bfs2021
bfs2021 changed the base branch from main to staging November 20, 2026 15:11
@github-actions github-actions Bot removed the not-following-guidelines The PR doesn't follow CONTRIBUTING.md yet label Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A wrong database key reaches clients through the single-key route and gRPC

2 participants