Skip to content

Commit 17a41c1

Browse files
authored
Ensure android initialization process continues even if options configuration block throws an exception (getsentry#3887)
* Ensure android event processors are added even if options configuration block throws * Changelog
1 parent cb0ecf1 commit 17a41c1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Ensure android initialization process continues even if options configuration block throws an exception ([#3887](https://github.com/getsentry/sentry-java/pull/3887))
8+
39
## 7.17.0
410

511
### Features

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,17 @@ public static synchronized void init(
129129
isTimberAvailable,
130130
isReplayAvailable);
131131

132-
configuration.configure(options);
132+
try {
133+
configuration.configure(options);
134+
} catch (Throwable t) {
135+
// let it slip, but log it
136+
options
137+
.getLogger()
138+
.log(
139+
SentryLevel.ERROR,
140+
"Error in the 'OptionsConfiguration.configure' callback.",
141+
t);
142+
}
133143

134144
// if SentryPerformanceProvider was disabled or removed,
135145
// we set the app start / sdk init time here instead

sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,19 @@ class SentryAndroidTest {
517517
assertEquals(99, AppStartMetrics.getInstance().appStartTimeSpan.startUptimeMs)
518518
}
519519

520+
@Test
521+
fun `if the config options block throws still intializes android event processors`() {
522+
lateinit var optionsRef: SentryOptions
523+
fixture.initSut(context = mock<Application>()) { options ->
524+
optionsRef = options
525+
options.dsn = "https://[email protected]/123"
526+
throw RuntimeException("Boom!")
527+
}
528+
529+
assertTrue(optionsRef.eventProcessors.any { it is DefaultAndroidEventProcessor })
530+
assertTrue(optionsRef.eventProcessors.any { it is AnrV2EventProcessor })
531+
}
532+
520533
private fun prefillScopeCache(cacheDir: String) {
521534
val scopeDir = File(cacheDir, SCOPE_CACHE).also { it.mkdirs() }
522535
File(scopeDir, BREADCRUMBS_FILENAME).writeText(

0 commit comments

Comments
 (0)