From fb6dccce1cd710cd2d9a991eb925f88773c5b50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beausoleil?= Date: Tue, 11 Mar 2008 10:40:25 -0400 Subject: [PATCH] Can't rescue CompilationError directly: must check the exception's class name instead. CompilationError is only available if RubyInline was loaded. --- lib/technoweenie/attachment_fu.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/technoweenie/attachment_fu.rb b/lib/technoweenie/attachment_fu.rb index 1c941b17..97aca8a7 100644 --- a/lib/technoweenie/attachment_fu.rb +++ b/lib/technoweenie/attachment_fu.rb @@ -84,7 +84,9 @@ def has_attachment(options = {}) processor_mod = Technoweenie::AttachmentFu::Processors.const_get(attachment_options[:processor]) include processor_mod unless included_modules.include?(processor_mod) end - rescue LoadError, MissingSourceFile, CompilationError + rescue Object, Exception + raise unless load_related_exception?($!) + processors.shift retry end @@ -92,11 +94,25 @@ def has_attachment(options = {}) begin processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor") include processor_mod unless included_modules.include?(processor_mod) - rescue LoadError, MissingSourceFile, CompilationError + rescue Object, Exception + raise unless load_related_exception?($!) + puts "Problems loading #{options[:processor]}Processor: #{$!}" end end unless parent_options[:processor] # Don't let child override processor end + + def load_related_exception?(e) #:nodoc: implementation specific + case + when e.kind_of?(LoadError), e.kind_of?(MissingSourceFile), $!.class.name == "CompilationError" + # We can't rescue CompilationError directly, as it is part of the RubyInline library. + # We must instead rescue RuntimeError, and check the class' name. + true + else + false + end + end + private :load_related_exception? end module ClassMethods