do not catch Worker exceptions

This commit is contained in:
Milos Kozak 2023-01-31 12:58:46 +01:00
parent 23e60084d0
commit 413d958c87

View file

@ -3,7 +3,6 @@ package info.nightscout.core.utils.worker
import android.content.Context import android.content.Context
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
@ -23,16 +22,10 @@ abstract class LoggingWorker(context: Context, workerParams: WorkerParameters, p
} }
override suspend fun doWork(): Result = override suspend fun doWork(): Result =
try { withContext(dispatcher) {
withContext(dispatcher) { doWorkAndLog().also {
doWorkAndLog().also { aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this@LoggingWorker::class.java}")
aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this@LoggingWorker::class.java}")
}
} }
} catch (e: Exception) {
fabricPrivacy.logException(e)
e.printStackTrace()
Result.failure(workDataOf("Error" to e.localizedMessage))
} }
abstract suspend fun doWorkAndLog(): Result abstract suspend fun doWorkAndLog(): Result