wallet+db: handle SQL backend errors#1200
wallet+db: handle SQL backend errors#1200yyforyongyu wants to merge 9 commits intobtcsuite:adr-0006-testsfrom
Conversation
d666be3 to
46801d8
Compare
46801d8 to
8c2cd43
Compare
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM ✅ (gpt-5.3-codex)
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM 🛡️
Error classification is correct — verified all PG SQLSTATE codes and SQLite result codes against official docs. Classification ordering in classifySQLError is sound (context errors first, then backend-specific, then generic connection, then permanent fallback). Stats counters are atomic. Error.Is correctly matches both class and reason sentinels.
Two minor observations (not bugs):
- Stats recorded during constructor error paths (
PingContext/ApplyMigrationsfailure) are discarded since the store is never returned. - A few common PG constraint codes (
23502,23P01) are not explicitly mapped but fall through correctly to permanent/unknown.
(claude-opus-4-6)
|
I've addressed both observations in the latest commit:
|
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM 🎲
The PR now includes:
- Detailed docs for error sentinels explaining when they occur
- Added and private sentinel types for type checking
- Switched to a switch-based approach derived from
- Clear documentation on pg and sqlite error specs
- Backend resolution happens before classification in
Good work addressing all the feedback! ()
|
LGTM 🚀 ( |
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM 🎲
The PR now includes:
- Detailed docs for error sentinels explaining when they occur
- Added errorClassSentinel and errorReasonSentinel private sentinel types for type checking
- Switched reasonRecorders to a switch-based approach derived from errorReasonSentinel
- Clear documentation on pg and sqlite error specs
- Backend resolution happens before classification in classifySQLError
Good work addressing all the feedback! (glm5)
4756bf7 to
bb6fdf3
Compare
bd96423 to
77c893f
Compare
Add the shared SQL error taxonomy, wrapper, and normalization helpers in the new db/err package. The API now uses shorter shared Class and Reason names so call sites avoid the earlier stutter. This also moves the shared error tests into the same package and adds docs for the remaining internal helpers.
Add the PostgreSQL SQLSTATE mapper in the new db/postgres package. The mapper converts PostgreSQL driver and transport failures into the shared SQL error model while keeping backend-specific helper details private to the package. This also moves the backend-specific mapper tests into the same package.
Add the SQLite result-code mapper in the new db/sqlite package. The mapper converts SQLite driver errors into the shared SQL error model while keeping backend-specific helper details private. This also moves the backend-specific mapper tests into the same package.
Add the shared SQL error stats collector and snapshot types to the db/err package. This keeps classification-driven metrics with the shared error framework instead of wiring them through top-level db production code first. This also adds focused unit coverage for the shared stats behavior.
Document the purpose of the shared db/err package and the intended boundaries between shared error code, backend-specific mapping, and runtime/store reaction policy. This keeps the staged package split explicit while production integration stays in follow-up work.
77c893f to
4fa0531
Compare
0511555 to
91a6ee6
Compare
4fa0531 to
215c824
Compare
Add the shared runtime helper package for SQL backends. The new helpers cover read retries, unhealthy-store checks, transaction execution, and ambiguous commit wrapping without wiring into backend store code yet. This keeps the runtime framework reviewable while store integration lands in follow-up work.
Add focused tests and small benchmarks for the shared runtime helper package. The coverage exercises retry, unhealthy-store, begin, and ambiguous-commit paths while the benchmarks cover the steady-state and transient-retry read flows.
6a30fad to
08832b6
Compare
Rename the shared error package declaration to err, keep dberr as\nthe import alias at call sites, and simplify the shared naming to\nClass and Reason throughout the package. The reason stringer now uses\none explicit switch and the same-package tests follow the renamed\npackage cleanly.\n\nThis also fills in the remaining mapper and helper docs so the shared\nerror framework matches the repo's Go documentation rules.
Rename the shared runtime hook interfaces and ambiguous-commit\nerror types to make their purpose clearer. Read retries now take\nexplicit caller-provided settings so future wallet or backend config\ncan own the retry policy instead of the shared helper package.\n\nThis also adds the missing helper docs and expands the tiny test\nhelpers to match the local multiline style.
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM 🎲
All review comments have been addressed. The PR now has:
- Clean package structure with shared
errpackage and backend-specificpostgres/sqlitepackages - Well-documented enums with
Valid()methods for backend, class, and reason - Clear
Reason.Class()method deriving policy from reason - Proper normalization helper that stays side-effect free
- README documenting package ownership boundaries
Good work on the iterations! (glm5)
|
LGTM 🚀 ( |
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM ✅ (gpt-5.3-codex)
yyforyongyu
left a comment
There was a problem hiding this comment.
LGTM 🛡️
All 21 PG SQLSTATE codes and 13 SQLite result codes verified against official docs — correctly classified. Reason.Class() range partitioning is correct. Normalize() ordering is sound (context first, existing wrappers preserved, backend-specific before generic transport, permanent fallback). pgconn.PgError is matched before SafeToRetry/Timeout so SQLSTATE codes are never shadowed. Stats counters atomic throughout. Retry loop boundaries correct with proper overflow handling in retryDelay. All 13 review threads resolved.
(claude-opus-4-6)
|
LGTM 🛡️ (qwen3.5-397b-a17b) All review threads resolved. The PR now includes:
Error classification logic is sound and well-documented. |
Summary
wallet/internal/db/err, including the shared taxonomy, wrapper, normalization helpers, stats collector, and package READMEwallet/internal/db/postgresandwallet/internal/db/sqlite, with same-package tests and private helper detailswallet/internal/db/runtimehelper framework for retry, unhealthy-store checks, transaction execution, and ambiguous commit handlingFollow-up Plan
wallet/internal/db/postgresandwallet/internal/db/sqliteTesting