Skip to content

Commit 178ff6d

Browse files
committed
Sync error recovery
1 parent 625fa83 commit 178ff6d

File tree

2 files changed

+192
-140
lines changed

2 files changed

+192
-140
lines changed

crates/core/src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use alloc::{
55
boxed::Box,
66
string::{String, ToString},
77
};
8+
use num_traits::FromPrimitive;
89
use sqlite_nostd::{context, sqlite3, Connection, Context, ResultCode};
910
use thiserror::Error;
1011

@@ -129,6 +130,20 @@ impl PowerSyncError {
129130
Internal { .. } => ResultCode::INTERNAL,
130131
}
131132
}
133+
134+
pub fn can_retry(&self) -> bool {
135+
match self.inner.as_ref() {
136+
RawPowerSyncError::Sqlite(cause) => {
137+
let base_error = ResultCode::from_i32((cause.code as i32) & 0xFF);
138+
if base_error == Some(ResultCode::BUSY) || base_error == Some(ResultCode::LOCKED) {
139+
true
140+
} else {
141+
false
142+
}
143+
}
144+
_ => false,
145+
}
146+
}
132147
}
133148

134149
impl Display for PowerSyncError {

0 commit comments

Comments
 (0)