From 12a2281cf41979c8158f2ba3048876ec1ae69958 Mon Sep 17 00:00:00 2001 From: Joshua Wood Date: Thu, 19 Oct 2023 15:27:24 -0700 Subject: [PATCH] Remove second opts argument in Honeybadger.notify This moves to keyword arguments exclusively. It's a breaking change because the following signature is no longer supported: Honeybadger.notify("test", {tags: 'testing, hash'}) --- lib/honeybadger/agent.rb | 3 +-- lib/honeybadger/singleton.rb | 4 ++-- spec/unit/honeybadger/agent_spec.rb | 29 +++-------------------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/lib/honeybadger/agent.rb b/lib/honeybadger/agent.rb index fd2e08cf..7281585d 100644 --- a/lib/honeybadger/agent.rb +++ b/lib/honeybadger/agent.rb @@ -119,9 +119,8 @@ def initialize(opts = {}) # # @return [String] UUID reference to the notice within Honeybadger. # @return [false] when ignored. - def notify(exception_or_opts = nil, opts = {}, **kwargs) + def notify(exception_or_opts = nil, **opts) opts = opts.dup - opts.merge!(kwargs) if exception_or_opts.is_a?(Exception) already_reported_notice_id = exception_or_opts.instance_variable_get(:@__hb_notice_id) diff --git a/lib/honeybadger/singleton.rb b/lib/honeybadger/singleton.rb index dc4f0161..3b920ae1 100644 --- a/lib/honeybadger/singleton.rb +++ b/lib/honeybadger/singleton.rb @@ -51,10 +51,10 @@ module Honeybadger # @!method notify(...) # Forwards to {Agent.instance}. # @see Agent#notify - def notify(exception_or_opts=nil, opts = {}, **kwargs) + def notify(exception_or_opts = nil, **opts) # Note this is defined directly (instead of via forwardable) so that # generated stack traces work as expected. - Agent.instance.notify(exception_or_opts, opts, **kwargs) + Agent.instance.notify(exception_or_opts, **opts) end # @api private diff --git a/spec/unit/honeybadger/agent_spec.rb b/spec/unit/honeybadger/agent_spec.rb index 6f78f29c..935a90d4 100644 --- a/spec/unit/honeybadger/agent_spec.rb +++ b/spec/unit/honeybadger/agent_spec.rb @@ -102,26 +102,15 @@ opts = {error_message: 'test'} prev = opts.dup instance = described_class.new(Honeybadger::Config.new(api_key: "fake api key", logger: NULL_LOGGER)) - instance.notify('test', opts) + instance.notify('test', **opts) expect(prev).to eq(opts) end - it "does take keyword arguments" do - opts = {error_message: 'test'} - config = Honeybadger::Config.new(api_key:'fake api key', logger: NULL_LOGGER) - instance = described_class.new(config) - - expect(instance.worker).to receive(:push) do |notice| - expect(notice.error_message).to match('test') - end - instance.notify(**opts) - end - - it "does take keyword arguments as second argument" do + it "accepts keyword arguments as second argument" do opts = {tags: 'testing, kwargs'} config = Honeybadger::Config.new(api_key:'fake api key', logger: NULL_LOGGER) instance = described_class.new(config) - + expect(instance.worker).to receive(:push) do |notice| expect(notice.error_message).to match('test') expect(notice.tags).to eq(['testing', 'kwargs']) @@ -129,18 +118,6 @@ instance.notify('test', **opts) end - it "does take explicit hash as second argument" do - opts = {tags: 'testing, hash'} - config = Honeybadger::Config.new(api_key:'fake api key', logger: NULL_LOGGER) - instance = described_class.new(config) - - expect(instance.worker).to receive(:push) do |notice| - expect(notice.error_message).to match('test') - expect(notice.tags).to eq(['testing', 'hash']) - end - instance.notify('test', opts) - end - it "does not report an already reported exception" do instance = described_class.new(Honeybadger::Config.new(api_key: "fake api key", logger: NULL_LOGGER)) exception = RuntimeError.new