Skip to content

NoMethodError in transaction_set_error when transaction is nil (SolidQueue)Β #1500

@afthabvp

Description

@afthabvp

Describe the bug

ActiveJobClassInstrumentation#transaction_set_error raises NoMethodError: undefined method 'set_error' for nil:NilClass when the transaction argument is nil. This happens in SolidQueue worker threads when Appsignal::Transaction.create fails and the job subsequently raises an exception.

To Reproduce

Steps to reproduce the behavior:

  1. Use SolidQueue as the ActiveJob backend
  2. A job fails in a SolidQueue worker thread where Appsignal::Transaction.create did not succeed
  3. The rescue block in ActiveJobClassInstrumentation#execute calls transaction_set_error(nil, exception)
  4. transaction_set_error calls nil.set_error(exception) β†’ NoMethodError

Error

SolidQueue-1.3.2 Error in thread (0.0ms) error: "NoMethodError undefined method `set_error' for nil:NilClass"

Traceback points to lib/appsignal/hooks/active_job.rb:122.

Root cause

In lib/appsignal/hooks/active_job.rb:

def transaction_set_error(transaction, exception)
  return unless Appsignal.config[:activejob_report_errors] == "all"
  transaction.set_error(exception)  # ← no nil guard
end

The method checks the config but does not check if transaction is nil before calling .set_error.

Suggested fix

def transaction_set_error(transaction, exception)
  return unless transaction
  return unless Appsignal.config[:activejob_report_errors] == "all"

  transaction.set_error(exception)
end

Environment
Ruby: 3.2.4
Rails: 7.1.1
appsignal: 4.8.3 (also reproducible on 3.7.5)
solid_queue: 1.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed and unconfirmed bugs reported by us and customers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions