Skip to content

Commit

Permalink
Remove second opts argument in Honeybadger.notify
Browse files Browse the repository at this point in the history
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'})
  • Loading branch information
joshuap committed Oct 19, 2023
1 parent e4a006c commit 12a2281
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
3 changes: 1 addition & 2 deletions lib/honeybadger/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/honeybadger/singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 3 additions & 26 deletions spec/unit/honeybadger/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,45 +102,22 @@
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'])
end
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
Expand Down

0 comments on commit 12a2281

Please sign in to comment.