@@ -2,6 +2,7 @@ package org.ooni.probe.data.repositories
2
2
3
3
import app.cash.sqldelight.coroutines.asFlow
4
4
import app.cash.sqldelight.coroutines.mapToList
5
+ import co.touchlab.kermit.Logger
5
6
import kotlinx.coroutines.flow.Flow
6
7
import kotlinx.coroutines.flow.map
7
8
import kotlinx.coroutines.withContext
@@ -180,7 +181,7 @@ class MeasurementRepository(
180
181
id = MeasurementModel .Id (id),
181
182
resultId = result_id?.let (ResultModel ::Id ) ? : return null ,
182
183
testName = test_name,
183
- testKeys = test_keys?.let { json.decodeFromString< TestKeys >(it) } ,
184
+ testKeys = test_keys?.let (::decodeTestKeys) ,
184
185
descriptorName = descriptor_name,
185
186
descriptorRunId = descriptor_runId?.let (InstalledTestDescriptorModel ::Id ),
186
187
)
@@ -191,9 +192,19 @@ class MeasurementRepository(
191
192
id = MeasurementModel .Id (id),
192
193
resultId = result_id?.let (ResultModel ::Id ) ? : return null ,
193
194
testName = test_name,
194
- testKeys = test_keys?.let { json.decodeFromString< TestKeys >(it) } ,
195
+ testKeys = test_keys?.let (::decodeTestKeys) ,
195
196
descriptorName = descriptor_name,
196
197
descriptorRunId = descriptor_runId?.let (InstalledTestDescriptorModel ::Id ),
197
198
)
198
199
}
200
+
201
+ private fun decodeTestKeys (value : String ): TestKeys ? {
202
+ if (value == " null" ) return null // Due to a past bug
203
+ return try {
204
+ json.decodeFromString<TestKeys >(value)
205
+ } catch (e: Exception ) {
206
+ Logger .e(" Invalid stored test_keys" , e)
207
+ null
208
+ }
209
+ }
199
210
}
0 commit comments