File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed
core/src/commonMain/kotlin/com/powersync/db Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -301,15 +301,23 @@ internal class PowerSyncDatabaseImpl(
301
301
302
302
private suspend fun updateHasSynced () {
303
303
// Query the database to see if any data has been synced.
304
- val timestamp = internalDb.getOptional(" SELECT powersync_last_synced_at() as synced_at" , null ) { cursor ->
305
- cursor.getString(0 )!!
306
- }
304
+ try {
305
+ val timestamp = internalDb.getOptional(" SELECT powersync_last_synced_at() as synced_at" , null ) { cursor ->
306
+ cursor.getString(0 )!!
307
+ }
307
308
308
- val hasSynced = timestamp != null
309
- if (hasSynced != currentStatus.hasSynced) {
310
- val formattedDateTime = " ${timestamp!! .replace(" " ," T" ).toLocalDateTime()} Z"
311
- val lastSyncedAt = Instant .parse(formattedDateTime)
312
- currentStatus.update(hasSynced = hasSynced, lastSyncedAt = lastSyncedAt)
309
+ val hasSynced = timestamp != null
310
+ if (hasSynced != currentStatus.hasSynced) {
311
+ val formattedDateTime = " ${timestamp!! .replace(" " ," T" ).toLocalDateTime()} Z"
312
+ val lastSyncedAt = Instant .parse(formattedDateTime)
313
+ currentStatus.update(hasSynced = hasSynced, lastSyncedAt = lastSyncedAt)
314
+ }
315
+ } catch (e: Exception ) {
316
+ if (e is NullPointerException ) {
317
+ // No data has been synced which results in a null pointer exception
318
+ // and can be safely ignored.
319
+ return
320
+ }
313
321
}
314
322
}
315
323
You can’t perform that action at this time.
0 commit comments