Skip to content

Commit

Permalink
Dup #notify opts before mutating (honeybadger-io#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidpraxis authored Feb 3, 2020
1 parent c27f1bf commit f6d048e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG](http://keepachangelog.com/) for how to update this file. This project
adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- Dup notify opts before mutating (#345)
### Changed
- Added Faktory plugin -@scottrobertson

Expand Down
2 changes: 2 additions & 0 deletions lib/honeybadger/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def initialize(opts = {})
# @return [String] UUID reference to the notice within Honeybadger.
# @return [false] when ignored.
def notify(exception_or_opts, opts = {})
opts = opts.dup

if exception_or_opts.is_a?(Exception)
opts[:exception] = exception_or_opts
elsif exception_or_opts.respond_to?(:to_hash)
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/honeybadger/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
instance.notify(error_message: 'testing backtrace generation')
end

it "does not mutate passed in opts" do
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)
expect(prev).to eq(opts)
end

it "calls all of the before notify hooks before sending" do
hooks = [spy("hook one", arity: 1), spy("hook two", arity: 1), spy("hook three", arity: 1)]
instance = described_class.new(Honeybadger::Config.new(api_key: "fake api key", logger: NULL_LOGGER))
Expand Down

0 comments on commit f6d048e

Please sign in to comment.