From f435f3829ff0d82201eccc83b89345a5b0f87a9b Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 4 May 2026 14:10:01 +0930 Subject: [PATCH] Discard block result during backend fallback AppProfiler.run normally returns the profile result, so we should be consistent. --- lib/app_profiler.rb | 1 + test/app_profiler/run_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/app_profiler.rb b/lib/app_profiler.rb index 655ac17..92383d4 100644 --- a/lib/app_profiler.rb +++ b/lib/app_profiler.rb @@ -100,6 +100,7 @@ def run(*args, backend: nil, **kwargs, &block) ) end yield + nil # no profile result ensure self.backend = original_backend if backend ProfileId::Current.reset diff --git a/test/app_profiler/run_test.rb b/test/app_profiler/run_test.rb index e4fde45..09f42ac 100644 --- a/test/app_profiler/run_test.rb +++ b/test/app_profiler/run_test.rb @@ -35,6 +35,17 @@ class RunTest < TestCase assert_operator profile.duration, :>=, 0.1 end + test ".run runs the block but does not return its result when the backend raises" do + ran = false + result = AppProfiler.run(backend: "not a real backend") do + ran = true + :block_value + end + + assert(ran) + assert_nil(result) + end + test ".run sets the backend then returns to the previous value" do orig_backend = AppProfiler.backend skip("Vernier not supported") unless AppProfiler.vernier_supported?