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:
- Use SolidQueue as the ActiveJob backend
- A job fails in a SolidQueue worker thread where
Appsignal::Transaction.create did not succeed
- The rescue block in
ActiveJobClassInstrumentation#execute calls transaction_set_error(nil, exception)
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
Describe the bug
ActiveJobClassInstrumentation#transaction_set_errorraisesNoMethodError: undefined method 'set_error' for nil:NilClasswhen thetransactionargument is nil. This happens in SolidQueue worker threads whenAppsignal::Transaction.createfails and the job subsequently raises an exception.To Reproduce
Steps to reproduce the behavior:
Appsignal::Transaction.createdid not succeedActiveJobClassInstrumentation#executecallstransaction_set_error(nil, exception)transaction_set_errorcallsnil.set_error(exception)→ NoMethodErrorError
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:The method checks the config but does not check if transaction is nil before calling .set_error.
Suggested fix
Environment
Ruby: 3.2.4
Rails: 7.1.1
appsignal: 4.8.3 (also reproducible on 3.7.5)
solid_queue: 1.3.2