Skip to content

Commit d4b2036

Browse files
runningcodeclaude
andcommitted
refactor(core): Consolidate scope-persistence error handling (JAVA-608)
Extract the duplicated try/catch in PersistingScopeObserver.serializeToDisk into a single runSafely helper used by both the on-executor and submit paths. Pure internal cleanup; error-handling behavior is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent aab952b commit d4b2036

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

sentry/src/main/java/io/sentry/cache/PersistingScopeObserver.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,30 +231,25 @@ private void serializeToDisk(final @NotNull Runnable task) {
231231
}
232232
if (Thread.currentThread().getName().contains("SentryExecutor")) {
233233
// we're already on the sentry executor thread, so we can just execute it directly
234-
try {
235-
task.run();
236-
} catch (Throwable e) {
237-
options.getLogger().log(ERROR, "Serialization task failed", e);
238-
}
234+
runSafely(task);
239235
return;
240236
}
241237

242238
try {
243-
options
244-
.getExecutorService()
245-
.submit(
246-
() -> {
247-
try {
248-
task.run();
249-
} catch (Throwable e) {
250-
options.getLogger().log(ERROR, "Serialization task failed", e);
251-
}
252-
});
239+
options.getExecutorService().submit(() -> runSafely(task));
253240
} catch (Throwable e) {
254241
options.getLogger().log(ERROR, "Serialization task could not be scheduled", e);
255242
}
256243
}
257244

245+
private void runSafely(final @NotNull Runnable task) {
246+
try {
247+
task.run();
248+
} catch (Throwable e) {
249+
options.getLogger().log(ERROR, "Serialization task failed", e);
250+
}
251+
}
252+
258253
private <T> void store(final @NotNull T entity, final @NotNull String fileName) {
259254
store(options, entity, fileName);
260255
}

0 commit comments

Comments
 (0)