From 6dec2650042c89d65e7a7d2ceecbaac756983e00 Mon Sep 17 00:00:00 2001 From: Jan Krutisch Date: Thu, 19 Oct 2023 17:56:36 +0200 Subject: [PATCH] FIX: Make notify work with proper ruby keyword arguments Fixes #426 --- lib/honeybadger/agent.rb | 7 ++++--- lib/honeybadger/singleton.rb | 4 ++-- spec/unit/honeybadger/agent_spec.rb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/honeybadger/agent.rb b/lib/honeybadger/agent.rb index 5700c61e..b43c6dae 100644 --- a/lib/honeybadger/agent.rb +++ b/lib/honeybadger/agent.rb @@ -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( diff --git a/lib/honeybadger/singleton.rb b/lib/honeybadger/singleton.rb index 53a57a60..dc4f0161 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, 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 diff --git a/spec/unit/honeybadger/agent_spec.rb b/spec/unit/honeybadger/agent_spec.rb index da18a88a..bb9dbe05 100644 --- a/spec/unit/honeybadger/agent_spec.rb +++ b/spec/unit/honeybadger/agent_spec.rb @@ -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