From a9bb228f8e978a50f5bafa6e5ec13aa9818622c9 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 6 Nov 2024 12:18:40 +0100 Subject: [PATCH] fix(image_processor): discard job on known errors --- app/jobs/image_processor_job.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/jobs/image_processor_job.rb b/app/jobs/image_processor_job.rb index fe5b356a4..0a4d3ee85 100644 --- a/app/jobs/image_processor_job.rb +++ b/app/jobs/image_processor_job.rb @@ -11,6 +11,16 @@ class ImageProcessorJob < ApplicationJob # If the file is deleted during the scan, ignore the error discard_on ActiveStorage::FileNotFoundError discard_on ActiveRecord::InvalidForeignKey + # If the file is not an image, not in format we can process or the image is corrupted, ignore the error + DISCARDABLE_ERRORS = [ + 'improper image header', + 'width or height exceeds limit', + 'attempt to perform an operation not allowed by the security policy', + 'no decode delegate for this image format' + ] + discard_on do |_, error| + DISCARDABLE_ERRORS.any? { error.message.match?(_1) } + end # If the file is not analyzed or scanned for viruses yet, retry later # (to avoid modifying the file while it is being scanned). retry_on FileNotScannedYetError, wait: :exponentially_longer, attempts: 10