diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index a0750a6b615..4b9898ce111 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,4 +1,6 @@ +* Skip logging rescuable exceptions which are defined in rescue_from/retry_on/discard_on. + *Hu Hailin* Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activejob/CHANGELOG.md) for previous changes. diff --git a/activejob/lib/active_job/log_subscriber.rb b/activejob/lib/active_job/log_subscriber.rb index 6fc32ca3c96..9886ba2d08c 100644 --- a/activejob/lib/active_job/log_subscriber.rb +++ b/activejob/lib/active_job/log_subscriber.rb @@ -54,8 +54,10 @@ module ActiveJob job = event.payload[:job] ex = event.payload[:exception_object] if ex - error do - "Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: #{ex.class} (#{ex.message}):\n" + Array(ex.backtrace).join("\n") + unless job.class.rescue_handlers.any? { |handler| handler[0] == event.payload[:exception][0] } + error do + "Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: #{ex.class} (#{ex.message}):\n" + Array(ex.backtrace).join("\n") + end end elsif event.payload[:aborted] error do