Skip to content

Commit 7d326e4

Browse files
committed
Don't create sqlite exceptions
1 parent 5d170c5 commit 7d326e4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

crates/core/src/error.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl PowerSyncError {
8686
RawPowerSyncError::MissingClientId.into()
8787
}
8888

89+
pub fn down_migration_did_not_update_version(current_version: i32) -> Self {
90+
return RawPowerSyncError::DownMigrationDidNotUpdateVersion { current_version }.into();
91+
}
92+
8993
/// Applies this error to a function result context, setting the error code and a descriptive
9094
/// text.
9195
pub fn apply_to_ctx(self, description: &str, ctx: *mut context) {
@@ -115,7 +119,9 @@ impl PowerSyncError {
115119
match self.inner.as_ref() {
116120
Sqlite { code, .. } => *code,
117121
ArgumentError { .. } | StateError { .. } => ResultCode::MISUSE,
118-
MissingClientId | SyncProtocolError { .. } => ResultCode::ABORT,
122+
MissingClientId
123+
| SyncProtocolError { .. }
124+
| DownMigrationDidNotUpdateVersion { .. } => ResultCode::ABORT,
119125
LocalDataError { .. } => ResultCode::CORRUPT,
120126
Internal { .. } => ResultCode::INTERNAL,
121127
}
@@ -192,6 +198,8 @@ enum RawPowerSyncError {
192198
LocalDataError { cause: PowerSyncErrorCause },
193199
#[error("No client_id found in ps_kv")]
194200
MissingClientId,
201+
#[error("Down migration failed - version not updated from {current_version}")]
202+
DownMigrationDidNotUpdateVersion { current_version: i32 },
195203
/// A catch-all for remaining internal errors that are very unlikely to happen.
196204
#[error("Internal PowerSync error. {cause}")]
197205
Internal { cause: PowerSyncErrorCause },

crates/core/src/migrations.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ CREATE TABLE IF NOT EXISTS ps_migration(id INTEGER PRIMARY KEY, down_migrations
8181
let new_version = current_version_stmt.column_int(0);
8282
if new_version >= current_version {
8383
// Database down from version $currentVersion to $version failed - version not updated after dow migration
84-
return Err(PowerSyncError::from_sqlite(
85-
ResultCode::ABORT,
86-
format!(
87-
"Down migration failed - version not updated from {:}",
88-
current_version
89-
),
84+
return Err(PowerSyncError::down_migration_did_not_update_version(
85+
current_version,
9086
));
9187
}
9288
current_version = new_version;

0 commit comments

Comments
 (0)