Skip to content

Commit dcc6bbf

Browse files
feat(init): Log why a properties file was not loaded (#4879)
* Log why a properties file was not loaded * Format code * fix(config): Trim whitespace on properties path (#4880) * Trim whitespace on properties file path * format * changelog * changelog --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent 9e3b01d commit dcc6bbf

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
- Removed SentryExecutorService limit for delayed scheduled tasks ([#4846](https://github.com/getsentry/sentry-java/pull/4846))
88
- Fix visual artifacts for the Canvas strategy on some devices ([#4861](https://github.com/getsentry/sentry-java/pull/4861))
9+
- [Config] Trim whitespace on properties path ([#4880](https://github.com/getsentry/sentry-java/pull/4880))
910
- Only set `DefaultReplayBreadcrumbConverter` if replay is available ([#4888](https://github.com/getsentry/sentry-java/pull/4888))
1011

1112
### Improvements
1213

1314
- Fallback to distinct-id as user.id logging attribute when user is not set ([#4847](https://github.com/getsentry/sentry-java/pull/4847))
1415
- Report Timber.tag() as `timber.tag` log attribute ([#4845](https://github.com/getsentry/sentry-java/pull/4845))
1516
- Session Replay: Add screenshot strategy serialization to RRWeb events ([#4851](https://github.com/getsentry/sentry-java/pull/4851))
17+
- Log why a properties file was not loaded ([#4879](https://github.com/getsentry/sentry-java/pull/4879))
1618

1719
### Dependencies
1820

sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.BufferedInputStream;
66
import java.io.File;
77
import java.io.FileInputStream;
8-
import java.io.IOException;
98
import java.io.InputStream;
109
import java.util.Properties;
1110
import org.jetbrains.annotations.NotNull;
@@ -24,15 +23,25 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log
2423
@Override
2524
public @Nullable Properties load() {
2625
try {
27-
final File f = new File(filePath);
26+
final File f = new File(filePath.trim());
2827
if (f.isFile() && f.canRead()) {
2928
try (InputStream is = new BufferedInputStream(new FileInputStream(f))) {
3029
final Properties properties = new Properties();
3130
properties.load(is);
3231
return properties;
3332
}
33+
} else if (!f.isFile()) {
34+
logger.log(
35+
SentryLevel.ERROR,
36+
"Failed to load Sentry configuration since it is not a file or does not exist: %s",
37+
filePath);
38+
} else if (!f.canRead()) {
39+
logger.log(
40+
SentryLevel.ERROR,
41+
"Failed to load Sentry configuration since it is not readable: %s",
42+
filePath);
3443
}
35-
} catch (IOException e) {
44+
} catch (Throwable e) {
3645
logger.log(
3746
SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", filePath);
3847
return null;

sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ class FilesystemPropertiesLoaderTest {
2222
assertEquals("some-dsn", properties["dsn"])
2323
}
2424

25+
@Test
26+
fun `returns properties when file has whitespace`() {
27+
val file = folder.newFile("sentry.properties")
28+
file.writeText("dsn=some-dsn", Charset.defaultCharset())
29+
val loader =
30+
FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance())
31+
val properties = loader.load()
32+
assertNotNull(properties)
33+
assertEquals("some-dsn", properties["dsn"])
34+
}
35+
2536
@Test
2637
fun `returns null when property file not found`() {
2738
val loader =

0 commit comments

Comments
 (0)