honeybadger-io / honeybadger-ruby

Ruby gem for reporting errors to honeybadger.io
https://docs.honeybadger.io/lib/ruby/
MIT License
250 stars 146 forks source link

exception if active job is configured to use a queue adapter via a class #560

Closed wlipa closed 4 months ago

wlipa commented 5 months ago

Rails no longer accepts ActiveJob queue adapters for new queuing backends into Rails itself; instead, one is supposed to configure the queue adapter by instantiating the class directly. However when this is done Honeybadger will throw an exception at startup because it expects QueueAdapters to have a .to_sym method. I don't think to_sym is documented anywhere as a requirement for an ActiveJob queue adapter.

See: https://github.com/rails/rails/pull/32298

initializer: config.active_job.queue_adapter = MyQueueAdapter.new

lib/my_queue_adapter.rb:

class MyQueueAdapter

  def enqueue(job)
    enqueue_at(job, Time.now)
  end

  def enqueue_at(job, timestamp)
    # custom
  end

end

results in:

** [Honeybadger] plugin error name=active_job class=NoMethodError message="undefined method `to_sym' for an instance of MyQueueAdapter"
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugins/active_job.rb:42:in `block (2 levels) in <module:ActiveJob>'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:121:in `instance_eval'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:121:in `call'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:240:in `block in ok?'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:240:in `all?'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:240:in `ok?'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:251:in `load!'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:96:in `block in load!'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:94:in `each_pair'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/plugin.rb:94:in `load!'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/singleton.rb:74:in `load_plugins!'
    /Users/wlipa/.gem/ruby/3.3.0/gems/honeybadger-5.11.1/lib/honeybadger/init/rails.rb:33:in `block in <class:Railtie>'
stympy commented 5 months ago

Thanks for the report! Give the handle_active_job_class_adapter branch a shot. :)

wlipa commented 4 months ago

Looks good.

stympy commented 4 months ago

5.11.2 has been released with this fix. Thanks for your help!