Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

throw an exception if DSN is not set #200

Merged
merged 3 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ static void applyMetadata(Context context, SentryAndroidOptions options) {
options.setAnrTimeoutIntervalMills(anrTimeoutIntervalMills);

String dsn = metadata.getString(DSN_KEY, null);
if (dsn != null) {
if (dsn == null) {
logIfNotNull(options.getLogger(), SentryLevel.FATAL, "DSN is required. Use empty string to disable SDK.");
} else if (dsn.isEmpty()) {
logIfNotNull(
options.getLogger(), SentryLevel.DEBUG, "DSN is empty, disabling sentry-android");
} else {
logIfNotNull(options.getLogger(), SentryLevel.DEBUG, "DSN read: %s", dsn);
options.setDsn(dsn);
}
options.setDsn(dsn);

boolean ndk = metadata.getBoolean(ENABLE_NDK, options.isEnableNdk());
logIfNotNull(options.getLogger(), SentryLevel.DEBUG, "NDK read: %s", ndk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SentryInitProviderTest {
}

@Test
fun `when applicationId is defined, dsn in meta-data is not set or null, SDK doesnt initialize`() {
fun `when applicationId is defined, dsn in meta-data is not set or null, SDK throws exception`() {
val providerInfo = ProviderInfo()

assertFalse(Sentry.isEnabled())
Expand All @@ -92,9 +92,7 @@ class SentryInitProviderTest {

metaData.putString(ManifestMetadataReader.DSN_KEY, null)

sentryInitProvider.attachInfo(mockContext, providerInfo)

assertFalse(Sentry.isEnabled())
assertFailsWith<IllegalArgumentException> { sentryInitProvider.attachInfo(mockContext, providerInfo) }
}

@Test
Expand Down
4 changes: 3 additions & 1 deletion sentry-core/src/main/java/io/sentry/core/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public static void init(@NotNull OptionsConfiguration<SentryOptions> optionsConf

private static synchronized <T extends SentryOptions> void init(@NotNull T options) {
String dsn = options.getDsn();
if (dsn == null || dsn.isEmpty()) {
if (dsn == null) {
throw new IllegalArgumentException("DSN is required. Use empty string to disable SDK.");
} else if (dsn.isEmpty()) {
close();
return;
}
Expand Down