NSC: resolve ack crash

This commit is contained in:
Milos Kozak 2022-12-27 18:32:47 +01:00
parent 43cef1e7b6
commit 3472f0f83e
2 changed files with 16 additions and 3 deletions

View file

@ -3,7 +3,9 @@ package info.nightscout.core.utils.worker
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import javax.inject.Inject
@ -11,14 +13,21 @@ import javax.inject.Inject
abstract class LoggingWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var fabricPrivacy: FabricPrivacy
init {
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
}
override fun doWork(): Result =
doWorkAndLog().also {
aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this::class.java}")
try {
doWorkAndLog().also {
aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this::class.java}")
}
} catch (e: Exception) {
fabricPrivacy.logException(e)
e.printStackTrace()
Result.failure(workDataOf("Error" to e.localizedMessage))
}
abstract fun doWorkAndLog(): Result

View file

@ -48,7 +48,11 @@ class NSClientAddAckWorker(
?: return Result.failure(workDataOf("Error" to "missing input data"))
if (sp.getBoolean(R.string.key_ns_sync_slow, false)) SystemClock.sleep(1000)
val ret = Result.success(workDataOf("ProcessedData" to ack.originalObject.toString()))
val ret = try {
Result.success(workDataOf("ProcessedData" to ack.originalObject.toString()))
} catch (e: Exception) {
Result.success(workDataOf("ProcessedData" to "huge record"))
}
when (ack.originalObject) {
is PairTemporaryTarget -> {