Skip to content

buzz-db: replace DbError::Sqlx with backend-neutral variants - #10110

Open
TheSentinel454 wants to merge 3 commits into
elrond/buzz-db-test-only-poolfrom
elrond/buzz-812-neutral-db-error
Open

TheSentinel454 wants to merge 3 commits into
elrond/buzz-db-test-only-poolfrom
elrond/buzz-812-neutral-db-error

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #10109. Merge that first.

Summary

DbError::Sqlx(sqlx::Error) exposed the driver error to every caller. Callers outside buzz-db matched SQLSTATE codes and sqlx::Error variants themselves, so they depended on the driver. This PR replaces it with variants that say what went wrong:

Variant Cause
Conflict SQLSTATE 23505, 23P01
LockTimeout SQLSTATE 55P03
Cancelled SQLSTATE 57014
Deadlock SQLSTATE 40P01
ReadOnly SQLSTATE 25006
Unavailable pool acquire timeout, closed pool, socket I/O
Database any other driver error

Each variant holds an opaque DriverError. Only buzz-db can open it, through pub(crate) fn driver(). From<sqlx::Error> is the only place that reads SQLSTATE codes. Migrate holds an opaque MigrationError the same way. Display text and source() are unchanged, so logs read the same.

DatastoreSpanError gains span_db_error. An error type outside buzz-db returns its DbError there, and the span records the same error type, SQLSTATE and constraint as before, without the caller naming sqlx. The old span_sqlx_error returned &sqlx::Error, so any crate could read SQLSTATE codes through it. It becomes span_driver_error, which returns an opaque SpanDriverError that only buzz-db can open. compile_fail doctests pin that SpanDriverError, DriverError and DbError::driver stay closed outside the crate.

Callers that matched codes now match variants: the relay thread-window API, the deletion-catalog readiness check, partition maintenance, and the deletion tests.

buzz-relay and buzz-audit now use sqlx only from their tests ([dev-dependencies]).

is_statement_cancelled, is_lock_timeout and is_connection_unavailable stay as one-line wrappers over the variants. The plan said to remove them. Keeping them avoids touching every caller in this PR; they can go once callers match variants directly.

What got simpler

  • One SQLSTATE classifier instead of matches spread across buzz-db, buzz-relay and buzz-deletion.
  • Two crates lose their production sqlx dependency.

Behavior

One small change. The thread-window API and the deletion-catalog readiness check used to treat only a pool acquire timeout as "database unavailable". They now also treat a closed pool and a socket error that way (503 / timeout), as the read API already did. Before, the API returned 500 for them. Readiness reported them as deletion_catalog_error; it now reports deletion_catalog_timeout. The relay is not ready either way; only the label changes.

Tests

  • New unit tests in buzz-db/src/error.rs: every SQLSTATE maps to its variant; only pool and I/O failures are Unavailable; driver variants keep the driver error for spans and logs.
  • The readiness test and a new thread-window unit test cover pool timeout, closed pool and socket I/O. The test-unit buzz-relay filter (and the scripts/run-tests.sh fallback) now selects api::bridge::thread_window::tests. The thread-window Postgres test keeps the real statement-timeout case.
  • The datastore-span runtime test now also covers an error outside buzz-db that wraps a DbError: its span keeps the SQLSTATE and constraint name.
  • compile_fail doctests for the closed driver accessors (run by cargo test -p buzz-db --doc).
  • Ran on Blox: cargo fmt --check; cargo check --workspace --lib --bins; cargo clippy --workspace --all-targets -- -D warnings; cargo nextest run -p buzz-db -p buzz-relay -p buzz-audit -p buzz-deletion -p buzz-search -p buzz-datastore-tracing --lib --tests --bins (2254 passed); cargo test -p buzz-db --doc. The Postgres lane runs in CI.

🤖 Generated with Claude Code

`DbError::Sqlx(sqlx::Error)` becomes variants that say what went wrong:
`Conflict` (23505, 23P01), `LockTimeout` (55P03), `Cancelled` (57014),
`Deadlock` (40P01), `ReadOnly` (25006), `Unavailable` (pool timeout,
closed pool, socket I/O) and a catch-all `Database`. Each holds an
opaque `DriverError` that only buzz-db can open. `From<sqlx::Error>` is
the one place that reads SQLSTATE codes to pick the variant. `Migrate`
holds an opaque `MigrationError` the same way.

`DatastoreSpanError` gains `span_db_error`, so an error type outside
buzz-db hands its `DbError` to the span without naming sqlx. The
`span_sqlx_error` hook is now hidden and only buzz-db overrides it.

Callers that matched SQLSTATE codes now match variants: the relay
thread-window API, the deletion-catalog readiness check, and partition
maintenance. The thread-window API and the readiness check now treat a
closed pool or a socket error like a pool timeout (503, timeout), as the
read API already does.

`buzz-relay` and `buzz-audit` now use sqlx only from their tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
TheSentinel454 and others added 2 commits December 1, 2026 21:34
`DatastoreSpanError::span_sqlx_error` returned `&sqlx::Error`, so a crate
outside buzz-db could still read SQLSTATE codes through it. It becomes
`span_driver_error`, which returns an opaque `SpanDriverError` that only
buzz-db can open. compile_fail doctests pin that `SpanDriverError`,
`DriverError` and `DbError::driver` stay closed outside the crate.

The datastore-span runtime test now also covers an error outside
buzz-db that wraps a `DbError`: its span keeps the SQLSTATE and
constraint name.

The thread-window outage cases (pool timeout, closed pool, socket
reset) move from the ignored Postgres test into a plain unit test of
`database_error`, so the unit lane runs them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
`api::bridge::thread_window::tests` matched no buzz-relay unit-lane
filter, so CI never ran the outage cases that moved there from the
Postgres test. Add the module to the `test-unit` filter and to the
Cargo fallback in scripts/run-tests.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>

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.

1 participant