Skip to content

Commit c2f43e7

Browse files
committed
fix: revert updateHasSynced change that removed null pointer handling
1 parent 0c38635 commit c2f43e7

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.0.0-BETA22
4+
* Revert `updateHasSynced` internal change that resulted in an error
5+
36
## 1.0.0-BETA21
47

58
* Improve error handling for Swift by adding @Throws annotation so errors can be handled in Swift

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,28 @@ internal class PowerSyncDatabaseImpl(
279279
}
280280

281281
private suspend fun updateHasSynced() {
282-
// Query the database to see if any data has been synced.
283-
val timestamp =
284-
internalDb.getOptional("SELECT powersync_last_synced_at() as synced_at", null) { cursor ->
285-
cursor.getString(0) ?: ""
282+
try {
283+
data class SyncedAt(
284+
val syncedAt: String?,
285+
)
286+
// Query the database to see if any data has been synced
287+
val timestamp =
288+
internalDb
289+
.getOptional("SELECT powersync_last_synced_at() as synced_at", null) { cursor ->
290+
SyncedAt(syncedAt = cursor.getStringOptional("synced_at"))
291+
}?.syncedAt
292+
val hasSynced = timestamp != null
293+
if (hasSynced != currentStatus.hasSynced) {
294+
val formattedDateTime = "${timestamp!!.replace(" ","T").toLocalDateTime()}Z"
295+
val lastSyncedAt = Instant.parse(formattedDateTime)
296+
currentStatus.update(hasSynced = hasSynced, lastSyncedAt = lastSyncedAt)
297+
}
298+
} catch (e: Exception) {
299+
if (e is NullPointerException) {
300+
// No data has been synced which results in a null pointer exception
301+
// and can be safely ignored.
302+
return
286303
}
287-
288-
val hasSynced = timestamp != ""
289-
if (hasSynced != currentStatus.hasSynced) {
290-
val formattedDateTime = "${timestamp!!.replace(" ", "T").toLocalDateTime()}Z"
291-
val lastSyncedAt = Instant.parse(formattedDateTime)
292-
currentStatus.update(hasSynced = hasSynced, lastSyncedAt = lastSyncedAt)
293304
}
294305
}
295306

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ development=true
1717
RELEASE_SIGNING_ENABLED=true
1818
# Library config
1919
GROUP=com.powersync
20-
LIBRARY_VERSION=1.0.0-BETA21
20+
LIBRARY_VERSION=1.0.0-BETA22
2121
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
2222
# POM
2323
POM_URL=https://github.com/powersync-ja/powersync-kotlin/

0 commit comments

Comments
 (0)