diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java b/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java index fcd4406a5f8..34a5da4f57e 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java @@ -43,7 +43,7 @@ public static String id(final @NotNull Context context) throws RuntimeException return deviceId; } deviceId = readInstallationFile(installation); - } catch (Throwable e) { + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt index 4ab9310d6b1..09f40e9234c 100644 --- a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt +++ b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt @@ -17,9 +17,11 @@ import io.sentry.exception.ExceptionMechanismException import io.sentry.exception.SentryHttpClientException import io.sentry.protocol.Mechanism import io.sentry.util.CookieUtils +import io.sentry.util.ExceptionUtils import io.sentry.util.HttpUtils import io.sentry.util.UrlUtils import java.util.concurrent.TimeUnit +import kotlin.coroutines.cancellation.CancellationException internal object SentryKtorClientUtils { internal suspend fun captureClientError( @@ -52,7 +54,12 @@ internal object SentryKtorClientUtils { statusCode = response.status.value try { bodySize = response.bodyAsBytes().size.toLong() - } catch (_: Throwable) {} + } catch (e: CancellationException) { + throw e + } catch (@Suppress("TooGenericExceptionCaught") e: Throwable) { + // The HTTP engine can throw anything while reading the body. The body size is optional. + ExceptionUtils.rethrowIfFatal(e) + } } event.request = sentryRequest diff --git a/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java b/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java index 137f1cd9156..c93d19ebf75 100644 --- a/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java +++ b/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java @@ -379,7 +379,7 @@ boolean ringRead(long position, byte[] buffer, int offset, int count) throws IOE resetFile(); } catch (IOException e) { throw e; - } catch (Throwable e) { + } catch (IndexOutOfBoundsException e) { // most likely the file is corrupt, so we delete it and recreate, accepting data loss resetFile(); }