From a19ce5518e678546fa1a631506b51b4a8876f403 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Tue, 28 Jan 2020 16:55:51 -0500 Subject: [PATCH] combine Rack::Timeout::RequestTimeoutErrors with Exceptions in Honeybadger (#5789) [deploy] --- config/initializers/honeybadger.rb | 1 + spec/initializers/honeybadger_spec.rb | 40 +------------------ .../sets_correct_honeybadger_fingerprint.rb | 9 +++++ spec/rails_helper.rb | 1 + 4 files changed, 13 insertions(+), 38 deletions(-) create mode 100644 spec/initializers/shared_examples/sets_correct_honeybadger_fingerprint.rb diff --git a/config/initializers/honeybadger.rb b/config/initializers/honeybadger.rb index 9b707a647..b75d15de7 100644 --- a/config/initializers/honeybadger.rb +++ b/config/initializers/honeybadger.rb @@ -4,6 +4,7 @@ MESSAGE_FINGERPRINTS = { "BANNED" => "banned", "Rack::Timeout::RequestTimeoutException" => "rack_timeout", + "Rack::Timeout::RequestTimeoutError" => "rack_timeout", "PG::QueryCanceled" => "pg_query_canceled" }.freeze diff --git a/spec/initializers/honeybadger_spec.rb b/spec/initializers/honeybadger_spec.rb index 0d780bf10..2e412ee4d 100644 --- a/spec/initializers/honeybadger_spec.rb +++ b/spec/initializers/honeybadger_spec.rb @@ -1,34 +1,8 @@ require "rails_helper" describe Honeybadger do - context "when a fetch_all_rss SIGTERM error is raised" do - it "sets fingerprint to error_message" do - notice = Honeybadger::Notice.new( - described_class.config, error_message: "SignalException: SIGTERM", component: "rake fetch_all_rss" - ) - described_class.config.before_notify_hooks.first.call(notice) - expect(notice.fingerprint).to eq(notice.error_message) - end - end - - context "when BANNED error is raised" do - it "sets fingerprint to banned" do - notice = Honeybadger::Notice.new( - described_class.config, error_message: "RuntimeError: BANNED" - ) - described_class.config.before_notify_hooks.first.call(notice) - expect(notice.fingerprint).to eq("banned") - end - end - - context "when Rack::Timeout::RequestTimeoutException is raised" do - it "sets fingerprint to rack_timeout" do - notice = Honeybadger::Notice.new( - described_class.config, error_message: "Rack::Timeout::RequestTimeoutException happened" - ) - described_class.config.before_notify_hooks.first.call(notice) - expect(notice.fingerprint).to eq("rack_timeout") - end + MESSAGE_FINGERPRINTS.each do |error_key, fingerprint| + include_examples "#sets_correct_honeybadger_fingerprint", error_key, fingerprint end context "when error is raised from an internal route" do @@ -40,14 +14,4 @@ describe Honeybadger do expect(notice.fingerprint).to eq("internal") end end - - context "when a PG::QueryCanceled error is raised" do - it "sets fingerprint to pg_query_cancel" do - notice = Honeybadger::Notice.new( - described_class.config, error_message: "ActionView::Template::Error: PG::QueryCanceled:" - ) - described_class.config.before_notify_hooks.first.call(notice) - expect(notice.fingerprint).to eq("pg_query_canceled") - end - end end diff --git a/spec/initializers/shared_examples/sets_correct_honeybadger_fingerprint.rb b/spec/initializers/shared_examples/sets_correct_honeybadger_fingerprint.rb new file mode 100644 index 000000000..3e2278add --- /dev/null +++ b/spec/initializers/shared_examples/sets_correct_honeybadger_fingerprint.rb @@ -0,0 +1,9 @@ +RSpec.shared_examples "#sets_correct_honeybadger_fingerprint" do |error_key, fingerprint| + it "raises an error" do + notice = Honeybadger::Notice.new( + described_class.config, error_message: "CRAP! #{error_key} Bail!" + ) + described_class.config.before_notify_hooks.first.call(notice) + expect(notice.fingerprint).to eq(fingerprint) + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 95b2ee625..cdac5084f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -34,6 +34,7 @@ Dir[Rails.root.join("spec/system/shared_examples/**/*.rb")].sort.each { |f| requ Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].sort.each { |f| require f } Dir[Rails.root.join("spec/jobs/shared_examples/**/*.rb")].sort.each { |f| require f } Dir[Rails.root.join("spec/workers/shared_examples/**/*.rb")].sort.each { |f| require f } +Dir[Rails.root.join("spec/initializers/shared_examples/**/*.rb")].sort.each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line.