From ca130d003fce7bba3ad686891a3ed1086f5b1c17 Mon Sep 17 00:00:00 2001 From: Roman Elizarov <elizarov@gmail.com> Date: Fri, 13 Nov 2020 12:00:29 +0300 Subject: [PATCH] Never report CancellationException (#1589) There is a number of place in the app with the following code pattern: try { // do some suspending operation } catch(e: Exception) { e.report(ExceptionCategory.EXPOSURENOTIFICATION) // or similar } In all such place if the corresponding suspending gets cancelled for any reason, the resulting CancellationException will get reported as an application crash. This fix prevents it from happening, since a cancellation exception is a part of a normal operation, not a failure that should be reported. --- .../coronawarnapp/exception/reporting/ExceptionReporter.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt index bdaf800b8..62b1aa914 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/reporting/ExceptionReporter.kt @@ -15,6 +15,7 @@ import de.rki.coronawarnapp.util.HasHumanReadableError import de.rki.coronawarnapp.util.tryHumanReadableError import java.io.PrintWriter import java.io.StringWriter +import java.util.concurrent.CancellationException fun Throwable.report(exceptionCategory: ExceptionCategory) = this.report(exceptionCategory, null, null) @@ -26,6 +27,10 @@ fun Throwable.report( ) { if (CWADebug.isAUnitTest) return + // CancellationException is a part of normal operation. It is used to cancel a running + // asynchronous operation. It is not a failure and should not be reported as such. + if (this is CancellationException) return + reportProblem(tag = prefix, info = suffix) val context = CoronaWarnApplication.getAppContext() -- GitLab