From 0c6f32a9f91e5e476d3c88f0b79a6f3b6dec53f5 Mon Sep 17 00:00:00 2001 From: HU Hailin Date: Fri, 25 Dec 2020 02:41:54 +0900 Subject: [PATCH] Skip logging rescuable exceptions which are defined in rescue_from/retry_on/discard_on. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update activejob/CHANGELOG.md Co-authored-by: Rafael França --- activejob/CHANGELOG.md | 2 ++ activejob/lib/active_job/log_subscriber.rb | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index a0750a6b61..4b9898ce11 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 6fc32ca3c9..9886ba2d08 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