Repository navigation
Document that iterating prepare(_:) crashes on SQLite errors - #1382
Merged
jberkel merged 1 commit intoOct 25, 2026
Merged
Conversation
The sequence `prepare(_:)` returns force-tries each step, so an error partway through the results (e.g. SQLITE_BUSY or an I/O error) aborts the app. The docs described this as throwing "undeclared" errors, and the README's first example uses `prepare(_:)` without a warning. - README: add a warning pointing to `prepareRowIterator(_:)` and the Failable iteration section. - Index.md: say the error aborts execution and can't be caught, and use `prepareRowIterator(_:)` in the Plucking Rows and Codable examples. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Related: #1383 proposes also deprecating |
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.
Iterating the sequence that
Connection.prepare(_:)returns goes throughFailableIterator.next(), which istry! failableNext(). So ifsqlite3_stepfails partway through the results (SQLITE_BUSYonce the busy timeout runs out,SQLITE_LOCKED, an I/O error, a corrupt page), the app crashes. It isn't a thrown error that ado/catchcan handle.The docs don't make this clear:
prepare(_:)with no warning. That's the API most people copy.Documentation/Index.mdsays the iterator "can throw undeclared database errors". It doesn't throw; it aborts execution.prepare(_:), even though the "Failable iteration" section just above them recommendsRowIterator.This PR changes documentation only:
prepareRowIterator(_:)and the Failable iteration section.try Array(db.prepareRowIterator(users))) and Codable (try db.prepareRowIterator(users).map { … }) examples toRowIterator.I compiled and ran the updated examples against current
master.Context: changing
next()totry?was tried in #1030 and reverted in #1075, and #1273 tried again but was closed. A non-throwingSequencecan't report an error partway through, so pointing people toRowIteratorseems like the practical fix.🤖 Generated with Claude Code