Skip to content

Commit

Permalink
add error when Proc raises
Browse files Browse the repository at this point in the history
  • Loading branch information
bmansoob committed Sep 5, 2024
1 parent 032840c commit 1c3f41b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/app_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ def profile_sampler_enabled
return false unless defined?(@profile_sampler_enabled)

@profile_sampler_enabled.is_a?(Proc) ? @profile_sampler_enabled.call : @profile_sampler_enabled
rescue
rescue => e
logger.error(
"[AppProfiler.profile_sampler_enabled] exception: #{e}, message: #{e.message}",
)
false
end

Expand Down
8 changes: 8 additions & 0 deletions test/app_profiler/app_profiler_configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,13 @@ class ConfigurationTest < TestCase
ensure
AppProfiler.profile_sampler_enabled = old_status
end

test "profile_sampler_enabled is false if Proc raises" do
old_status = AppProfiler.profile_sampler_enabled
AppProfiler.profile_sampler_enabled = -> { raise "error" }
assert_equal(false, AppProfiler.profile_sampler_enabled)
ensure
AppProfiler.profile_sampler_enabled = old_status
end
end
end

0 comments on commit 1c3f41b

Please sign in to comment.