Repository navigation
buzz-db: replace DbError::Sqlx with backend-neutral variants - #10110
Open
TheSentinel454 wants to merge 3 commits into
Open
TheSentinel454 wants to merge 3 commits into
TheSentinel454 wants to merge 3 commits into
Conversation
`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
requested review from
a team,
bradseiler,
ravarora2,
salman1993 and
wpfleger96
as code owners
December 2, 2026 02:29
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #10109. Merge that first.
Summary
DbError::Sqlx(sqlx::Error)exposed the driver error to every caller. Callers outsidebuzz-dbmatched SQLSTATE codes andsqlx::Errorvariants themselves, so they depended on the driver. This PR replaces it with variants that say what went wrong:ConflictLockTimeoutCancelledDeadlockReadOnlyUnavailableDatabaseEach variant holds an opaque
DriverError. Onlybuzz-dbcan open it, throughpub(crate) fn driver().From<sqlx::Error>is the only place that reads SQLSTATE codes.Migrateholds an opaqueMigrationErrorthe same way. Display text andsource()are unchanged, so logs read the same.DatastoreSpanErrorgainsspan_db_error. An error type outsidebuzz-dbreturns itsDbErrorthere, and the span records the same error type, SQLSTATE and constraint as before, without the caller naming sqlx. The oldspan_sqlx_errorreturned&sqlx::Error, so any crate could read SQLSTATE codes through it. It becomesspan_driver_error, which returns an opaqueSpanDriverErrorthat onlybuzz-dbcan open.compile_faildoctests pin thatSpanDriverError,DriverErrorandDbError::driverstay 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-relayandbuzz-auditnow use sqlx only from their tests ([dev-dependencies]).is_statement_cancelled,is_lock_timeoutandis_connection_unavailablestay 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
buzz-db,buzz-relayandbuzz-deletion.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 reportsdeletion_catalog_timeout. The relay is not ready either way; only the label changes.Tests
buzz-db/src/error.rs: every SQLSTATE maps to its variant; only pool and I/O failures areUnavailable; driver variants keep the driver error for spans and logs.test-unitbuzz-relay filter (and thescripts/run-tests.shfallback) now selectsapi::bridge::thread_window::tests. The thread-window Postgres test keeps the real statement-timeout case.buzz-dbthat wraps aDbError: its span keeps the SQLSTATE and constraint name.compile_faildoctests for the closed driver accessors (run bycargo test -p buzz-db --doc).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