diff --git a/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt b/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt index 8f3ae52609..4b926df341 100644 --- a/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt +++ b/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt @@ -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 diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt index ed3065b845..baf753202e 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt @@ -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 -> {