-
-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
Summary
GenerationJob#handle_exception_with_agent_class calls klass.handle_exception(exception) (a class method), but the Rescue concern only defines instance methods. This causes a NoMethodError when a job-level exception is raised.
Steps to Reproduce
Any agent that uses generate_later and encounters an unhandled exception in the job:
class MyAgent < ActiveAgent::Base
rescue_from StandardError, with: :handle_error
def handle_error(exception)
Rails.logger.error exception.message
end
endWhen an exception propagates to the job level, GenerationJob tries to call:
klass.handle_exception exception # NoMethodError — no such class methodRoot Cause
In lib/active_agent/generation_job.rb:43:
def handle_exception_with_agent_class(exception)
if klass = agent_class
klass.handle_exception exception # ← class method call
else
raise exception
end
endThe Rescue concern (lib/active_agent/concerns/rescue.rb) only defines instance methods:
handle_exceptions(instance method, different name)process(instance method)exception_handler(instance method)
There is no self.handle_exception class method defined anywhere in the gem.
Current Workaround
Users must define the missing class method themselves:
class ApplicationAgent < ActiveAgent::Base
def self.handle_exception(exception)
Rails.logger.error "[#{name}] #{exception.class}: #{exception.message}"
Rails.logger.error exception.backtrace&.first(10)&.join("\n") if exception.backtrace
end
endSuggested Fix
Add a handle_exception class method to the Rescue concern:
class_methods do
def handle_exception(exception)
ActiveSupport::Notifications.instrument("rescue_from_callback.active_agent", exception: exception)
Rails.logger.error "[#{name}] #{exception.class}: #{exception.message}"
Rails.logger.error exception.backtrace&.first(10)&.join("\n") if exception.backtrace
end
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels