From d4b2036d96674b1499bd427f38a379c9b9caa6e1 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 2 Jul 2026 18:56:35 +0200 Subject: [PATCH] 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 --- .../sentry/cache/PersistingScopeObserver.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/sentry/src/main/java/io/sentry/cache/PersistingScopeObserver.java b/sentry/src/main/java/io/sentry/cache/PersistingScopeObserver.java index c9356579c9c..edfcc71b9a6 100644 --- a/sentry/src/main/java/io/sentry/cache/PersistingScopeObserver.java +++ b/sentry/src/main/java/io/sentry/cache/PersistingScopeObserver.java @@ -231,30 +231,25 @@ private void serializeToDisk(final @NotNull Runnable task) { } if (Thread.currentThread().getName().contains("SentryExecutor")) { // we're already on the sentry executor thread, so we can just execute it directly - try { - task.run(); - } catch (Throwable e) { - options.getLogger().log(ERROR, "Serialization task failed", e); - } + runSafely(task); return; } try { - options - .getExecutorService() - .submit( - () -> { - try { - task.run(); - } catch (Throwable e) { - options.getLogger().log(ERROR, "Serialization task failed", e); - } - }); + options.getExecutorService().submit(() -> runSafely(task)); } catch (Throwable e) { options.getLogger().log(ERROR, "Serialization task could not be scheduled", e); } } + private void runSafely(final @NotNull Runnable task) { + try { + task.run(); + } catch (Throwable e) { + options.getLogger().log(ERROR, "Serialization task failed", e); + } + } + private void store(final @NotNull T entity, final @NotNull String fileName) { store(options, entity, fileName); }