From 82be5d033f9a5e9335d4efee6008439c7770f102 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 7 Jun 2024 17:39:41 +0200 Subject: [PATCH] Improve handling of libvips failures (#30597) --- lib/paperclip/blurhash_transcoder.rb | 2 ++ lib/paperclip/color_extractor.rb | 2 ++ lib/paperclip/vips_lazy_thumbnail.rb | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/paperclip/blurhash_transcoder.rb b/lib/paperclip/blurhash_transcoder.rb index e9cecef50..150275bc9 100644 --- a/lib/paperclip/blurhash_transcoder.rb +++ b/lib/paperclip/blurhash_transcoder.rb @@ -12,6 +12,8 @@ module Paperclip attachment.instance.blurhash = Blurhash.encode(width, height, data, **(options[:blurhash] || {})) @file + rescue Vips::Error => e + raise Paperclip::Error, "Error while generating blurhash for #{@basename}: #{e}" end private diff --git a/lib/paperclip/color_extractor.rb b/lib/paperclip/color_extractor.rb index b5992f90b..0f168d233 100644 --- a/lib/paperclip/color_extractor.rb +++ b/lib/paperclip/color_extractor.rb @@ -69,6 +69,8 @@ module Paperclip attachment.instance.file.instance_write(:meta, (attachment.instance.file.instance_read(:meta) || {}).merge(meta)) @file + rescue Vips::Error => e + raise Paperclip::Error, "Error while extracting colors for #{@basename}: #{e}" end private diff --git a/lib/paperclip/vips_lazy_thumbnail.rb b/lib/paperclip/vips_lazy_thumbnail.rb index 06d99bf79..4764b04af 100644 --- a/lib/paperclip/vips_lazy_thumbnail.rb +++ b/lib/paperclip/vips_lazy_thumbnail.rb @@ -68,7 +68,7 @@ module Paperclip end dst - rescue Terrapin::ExitStatusError => e + rescue Vips::Error, Terrapin::ExitStatusError => e raise Paperclip::Error, "Error while optimizing #{@basename}: #{e}" rescue Terrapin::CommandNotFoundError raise Paperclip::Errors::CommandNotFoundError, 'Could not run the `ffmpeg` command. Please install ffmpeg.'