Skip to content

Commit

Permalink
FIX: Make notify work with proper ruby keyword arguments
Browse files Browse the repository at this point in the history
Fixes #426
  • Loading branch information
halfbyte committed Oct 19, 2023
1 parent 15a5766 commit 6dec265
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/honeybadger/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,21 @@ def initialize(opts = {})
#
# @return [String] UUID reference to the notice within Honeybadger.
# @return [false] when ignored.
def notify(exception_or_opts, opts = {})
def notify(exception_or_opts=nil, opts={}, **kwargs)
opts = opts.dup

if exception_or_opts.is_a?(Exception)
already_reported_notice_id = exception_or_opts.instance_variable_get(:@__hb_notice_id)
return already_reported_notice_id if already_reported_notice_id

opts[:exception] = exception_or_opts
elsif exception_or_opts.respond_to?(:to_hash)
opts.merge!(exception_or_opts.to_hash)
else
elsif !exception_or_opts.nil?
opts[:error_message] = exception_or_opts.to_s
end

opts = opts.merge(kwargs)

validate_notify_opts!(opts)

add_breadcrumb(
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, opts = {})
def notify(exception_or_opts=nil, opts = {}, **kwargs)
# Note this is defined directly (instead of via forwardable) so that
# generated stack traces work as expected.
Agent.instance.notify(exception_or_opts, opts)
Agent.instance.notify(exception_or_opts, opts, **kwargs)
end

# @api private
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/honeybadger/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
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

Expand Down

0 comments on commit 6dec265

Please sign in to comment.