diff --git a/CHANGELOG.md b/CHANGELOG.md index f342737d994..ebb582c096c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Removed SentryExecutorService limit for delayed scheduled tasks ([#4846](https://github.com/getsentry/sentry-java/pull/4846)) - Fix visual artifacts for the Canvas strategy on some devices ([#4861](https://github.com/getsentry/sentry-java/pull/4861)) +- [Config] Trim whitespace on properties path ([#4880](https://github.com/getsentry/sentry-java/pull/4880)) - Only set `DefaultReplayBreadcrumbConverter` if replay is available ([#4888](https://github.com/getsentry/sentry-java/pull/4888)) ### Improvements @@ -13,6 +14,7 @@ - Fallback to distinct-id as user.id logging attribute when user is not set ([#4847](https://github.com/getsentry/sentry-java/pull/4847)) - Report Timber.tag() as `timber.tag` log attribute ([#4845](https://github.com/getsentry/sentry-java/pull/4845)) - Session Replay: Add screenshot strategy serialization to RRWeb events ([#4851](https://github.com/getsentry/sentry-java/pull/4851)) +- Log why a properties file was not loaded ([#4879](https://github.com/getsentry/sentry-java/pull/4879)) ### Dependencies diff --git a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java index de93d5bbad6..dcb1ea91009 100644 --- a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java +++ b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java @@ -5,7 +5,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.jetbrains.annotations.NotNull; @@ -24,15 +23,25 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log @Override public @Nullable Properties load() { try { - final File f = new File(filePath); + final File f = new File(filePath.trim()); if (f.isFile() && f.canRead()) { try (InputStream is = new BufferedInputStream(new FileInputStream(f))) { final Properties properties = new Properties(); properties.load(is); return properties; } + } else if (!f.isFile()) { + logger.log( + SentryLevel.ERROR, + "Failed to load Sentry configuration since it is not a file or does not exist: %s", + filePath); + } else if (!f.canRead()) { + logger.log( + SentryLevel.ERROR, + "Failed to load Sentry configuration since it is not readable: %s", + filePath); } - } catch (IOException e) { + } catch (Throwable e) { logger.log( SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", filePath); return null; diff --git a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt index 11e3a3a3fbc..1addfb449bc 100644 --- a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt @@ -22,6 +22,17 @@ class FilesystemPropertiesLoaderTest { assertEquals("some-dsn", properties["dsn"]) } + @Test + fun `returns properties when file has whitespace`() { + val file = folder.newFile("sentry.properties") + file.writeText("dsn=some-dsn", Charset.defaultCharset()) + val loader = + FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance()) + val properties = loader.load() + assertNotNull(properties) + assertEquals("some-dsn", properties["dsn"]) + } + @Test fun `returns null when property file not found`() { val loader =