bugsnag / bugsnag-ruby

BugSnag error monitoring & reporting software for rails, sinatra, rack and ruby
https://docs.bugsnag.com/platforms/ruby
MIT License
245 stars 173 forks source link

Allow overriding an event's unhandled flag #698

Closed imjoehaines closed 2 years ago

imjoehaines commented 3 years ago

Goal

This PR allows overriding an event's unhandled flag, for example to mark a handled error as unhandled within a notify block:

Bugsnag.notify(some_error) do |event|
  event.unhandled = true
end

The inverse also works — unhandled events can be marked as handled:

Bugsnag.add_on_error(proc do |event|
  event.unhandled = false

  # it may also make sense to modify the severity as well
  event.severity = "warning"
end)

This will also update the associated session (if there is one) to ensure the count of handled/unhandled events remains consistent. This happens when the unhandled flag is written to, e.g.

Bugsnag.notify(BugsnagTestException.new("It crashed")) do |event|
  expect(event.session[:events]).to eq({ handled: 1, unhandled: 0 })

  report.unhandled = true

  expect(event.session[:events]).to eq({ handled: 0, unhandled: 1 })
end