Improve error handling - #211
Merged
Merged
Conversation
simolus3
marked this pull request as ready for review
August 5, 2026 08:43
stevensJourney
approved these changes
Aug 5, 2026
stevensJourney
left a comment
Contributor
There was a problem hiding this comment.
This looks like a nice improvement. Changes look good to me.
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.
In powersync-ja/powersync.dart#453 (comment), we've gotten a report where the core extension reports an error like this (emphasis is the part from the extension):
That doesn't help much to understand the problem: Some statement ran by
powersync_controlhas failed, but which one?This PR removes the
From<ResultCode>implementation forPowerSyncError, forcing us to provide more specific details when returning errors. Essentially, this statically prevents forgetting to callinto_db_result. But eveninto_db_result, which adds more context into errors, wouldn't include the failed statement. So, this adds our own database (Database, replacing*mut sqlite3) and statement (Statement, replacingManagedStmt) wrappers which, instead of returning aResultCodeerror, will automatically return aPowerSyncErrorwith appropriate context and the causing SQL statement.These wrappers also simplify some things:
ResultCodein theOkcase,step()now returns aResult<bool>indicating whether a row is available.db.execwith a&strwould allocate aCStringto pass to SQLite. This replaces the method with something taking a&CStrdirectly (avoiding a copy for literals).PowerSyncErrors to be wrapped with additional context, this was previously only possible forResultCode-backed errors.AI use: The new helpers are manually written, migrating the rest of the crate was done mechanically with string replacements and AI.
I also ran this through a Code Review with Claude Code to confirm existing behavior is unchanged.