From 4130f3d21782e15dcc07b054f71c006ca845db2a Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Wed, 21 Oct 2020 11:31:40 +0100 Subject: [PATCH] Allow classes to be passed into `data_sync_excluded_exceptions` This maintains parity with the Raven interface: https://github.com/getsentry/sentry-ruby/blob/7a0cebc54c5508d379769c7af688c8218721d734/lib/raven/configuration.rb#L447 --- lib/govuk_app_config/govuk_error/configuration.rb | 2 +- spec/govuk_error/configuration_spec.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/govuk_app_config/govuk_error/configuration.rb b/lib/govuk_app_config/govuk_error/configuration.rb index 44fcfc56..9fedb0d6 100644 --- a/lib/govuk_app_config/govuk_error/configuration.rb +++ b/lib/govuk_app_config/govuk_error/configuration.rb @@ -25,7 +25,7 @@ def should_capture=(closure) def ignore_excluded_exceptions_in_data_sync lambda { |error_or_event| data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore| - exception_to_ignore = Object.const_get(exception_to_ignore) + exception_to_ignore = Object.const_get(exception_to_ignore) unless exception_to_ignore.is_a?(Module) exception_chain = Raven::Utils::ExceptionCauseChain.exception_to_array(error_or_event) exception_chain.any? { |exception| exception.is_a?(exception_to_ignore) } rescue NameError diff --git a/spec/govuk_error/configuration_spec.rb b/spec/govuk_error/configuration_spec.rb index 042c0ce9..676522ee 100644 --- a/spec/govuk_error/configuration_spec.rb +++ b/spec/govuk_error/configuration_spec.rb @@ -27,12 +27,18 @@ expect(configuration.should_capture.call(StandardError.new)).to eq(true) end - it "should ignore errors that have been added to data_sync_excluded_exceptions" do + it "should ignore errors that have been added as a string to data_sync_excluded_exceptions" do configuration.data_sync_excluded_exceptions << "StandardError" expect(configuration.should_capture.call(StandardError.new)).to eq(false) end + it "should ignore errors that have been added as a class to data_sync_excluded_exceptions" do + configuration.data_sync_excluded_exceptions << StandardError + + expect(configuration.should_capture.call(StandardError.new)).to eq(false) + end + it "should ignore errors whose underlying cause is an exception in data_sync_excluded_exceptions" do stub_const("ErrorWeCareAbout", Class.new(StandardError)) stub_const("SomeOtherError", Class.new(StandardError))