Skip to content

Commit 272f328

Browse files
committed
fix(firmware): guard staleWhileRevalidate cache reads
Wrap both loadFromCache calls in staleWhileRevalidateFlow with safeCatching so a cache-read failure logs and returns null instead of throwing into the caller. This prevents a DB error during release cache reads from clobbering a recovery Ready state with a generic error on the recovery path.
1 parent 41be20a commit 272f328

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

core/data/src/commonMain/kotlin/org/meshtastic/core/data/util/StaleWhileRevalidateFlow.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ internal fun <T : Any> staleWhileRevalidateFlow(
5454
networkTimeoutMs: Long? = DEFAULT_NETWORK_TIMEOUT_MS,
5555
tag: String = "StaleWhileRevalidate",
5656
): Flow<T?> = flow {
57-
val cached = loadFromCache()
57+
val cached =
58+
safeCatching { loadFromCache() }
59+
.onFailure { e -> Logger.w(e) { "$tag: cache read failed" } }
60+
.getOrNull()
5861
emit(cached)
5962

6063
if (!shouldFetch(cached)) return@flow
@@ -78,7 +81,10 @@ internal fun <T : Any> staleWhileRevalidateFlow(
7881
Logger.w { "$tag: network fetch timed out after ${networkTimeoutMs}ms" }
7982
}
8083

81-
val fresh = loadFromCache()
84+
val fresh =
85+
safeCatching { loadFromCache() }
86+
.onFailure { e -> Logger.w(e) { "$tag: cache reload failed after fetch" } }
87+
.getOrNull()
8288
if (fresh != cached) {
8389
emit(fresh)
8490
}

0 commit comments

Comments
 (0)