Repository navigation
Microsoft.Data.Sqlite: Include extended error code and guidance in SqliteException messages - #39588
Open
ajcvickers wants to merge 2 commits into
Open
ajcvickers wants to merge 2 commits into
ajcvickers wants to merge 2 commits into
Conversation
Contributor
Author
|
/cc @bricelam |
…essages Append the extended error code (with its symbolic name where known) when it differs from the primary code, and add guidance for SQLITE_BUSY_SNAPSHOT and SQLITE_BUSY. Part of dotnet#29514 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ajcvickers
force-pushed
the
sqlite-extended-error-guidance
branch
from
November 14, 2026 11:40
10b8d3d to
7cc65f3
Compare
… names - BUSY_SNAPSHOT guidance now says to roll back and retry the transaction, and that disposing readers only helps outside a transaction. - Name every extended error code from the SQLite result code list, declaring locally the ones SQLitePCL.raw doesn't define (e.g. SQLITE_CONSTRAINT_DATATYPE, which STRICT tables raise). - Show the name even when extended result codes are enabled and the primary and extended codes are equal. - Tests: cover a deferred transaction that writes after another connection commits, a STRICT table type violation and extended result codes; remove the backup test that asserted on text nothing produces; reuse DeleteDatabase; assert the full message in CreateCollation_with_null_comparer_works. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Part of #29514
Exception messages from Microsoft.Data.Sqlite included the primary SQLite error code but not the extended one, which is often what identifies the real cause. For #29514 the message was just
SQLite Error 5: 'database is locked'., while the underlying error wasSQLITE_BUSY_SNAPSHOT(517).When
SqliteException.ThrowExceptionForRCbuilds a message, it now:Extended error code: N (NAME).when the extended code differs from the primary code, with the symbolic name for every extended error code in the SQLite result code list (the name is also shown when extended result codes are enabled, in which case the primary and extended codes are equal). For example, a unique violation now readsSQLite Error 19: 'UNIQUE constraint failed: Data.Value'. Extended error code: 2067 (SQLITE_CONSTRAINT_UNIQUE).SQLITE_BUSY_SNAPSHOT: this happens when a connection with an open read transaction writes after another connection committed, waiting can't help, and the fix is to roll back and retry the transaction. To avoid it, start a non-deferred transaction before reading, and outside a transaction dispose any open readers before writing.The existing
SQLite Error N: '...'.prefix is unchanged, so anything matching on it keeps working. Messages for errors where the extended code equals the primary code are identical to before. Anyone comparing the fullMessageof an error that has an extended code (e.g.SQLITE_CONSTRAINT_*) will see the extra text, so this is a (minor) breaking change that should go in the release notes.SQLitePCL doesn't define some extended codes (for example
SQLITE_ERROR_MISSING_COLLSEQandSQLITE_CONSTRAINT_DATATYPE, which STRICT tables raise), so those are declared locally with their documented values.Deliberately no guidance for plain
SQLITE_BUSYPlain
SQLITE_BUSYhas several causes (another writer,BackupDatabase, which doesn't use the timeout at all, and so on), and advice that mentions the timeout or WAL would be wrong for some of them.Tests
FormatMessagetheory covers named and unnamed extended codes and which codes get guidance.SQLITE_BUSY(no guidance), andBackupDatabasebeing busy (message doesn't mention a timeout).ThrowExceptionForRCpath with no database handle is covered too.CreateCollation_with_null_comparer_worksnow asserts the full message, because that error carries extended code 257.Related
#39587 makes Microsoft.Data.Sqlite throw immediately for
SQLITE_BUSY_SNAPSHOTinstead of retrying until the timeout. The two PRs are independent, but this one should merge after #39587: without it, a primarySQLITE_BUSY_SNAPSHOTis still retried until the timeout, so users wait the fullDefault Timeoutbefore they see "Waiting cannot help". Until that one merges, the stale-snapshot test here setsDefault Timeout=1so it doesn't wait 30 seconds, and it could drop that once both have landed.🤖 Generated with Claude Code