Commit e195ef66 by Adam Niedzielski Committed by Mike Burns

Only rescue exceptions we can handle

Rescue only `NotIdentifiedByImageMagickError` in
`Attachment#post_process_style`. Other errors should bubble up, because
they are meaningless for the end-user, but important for the programmer.

Fixes #1352.
parent 85e9663a
......@@ -528,7 +528,7 @@ module Paperclip
@queued_for_write[name] = Paperclip.io_adapters.for(@queued_for_write[name])
unadapted_file.close if unadapted_file.respond_to?(:close)
@queued_for_write[name]
rescue Paperclip::Error => e
rescue Paperclip::Errors::NotIdentifiedByImageMagickError => e
log("An error was received while processing: #{e.inspect}")
(@errors[:processing] ||= []) << e.message if @options[:whiny]
ensure
......
......@@ -635,15 +635,40 @@ describe Paperclip::Attachment do
before do
rebuild_model processor: [:thumbnail], styles: { small: '' }, whiny_thumbnails: true
@dummy = Dummy.new
Paperclip::Thumbnail.expects(:make).raises(Paperclip::Error, "cannot be processed.")
@file = StringIO.new("...")
@file.stubs(:to_tempfile).returns(@file)
@dummy.avatar = @file
end
context "when error is meaningful for the end user" do
before do
Paperclip::Thumbnail.expects(:make).raises(
Paperclip::Errors::NotIdentifiedByImageMagickError,
"cannot be processed."
)
end
it "correctly forwards processing error message to the instance" do
@dummy.avatar = @file
@dummy.valid?
assert_contains @dummy.errors.full_messages, "Avatar cannot be processed."
assert_contains(
@dummy.errors.full_messages,
"Avatar cannot be processed."
)
end
end
context "when error is intended for the developer" do
before do
Paperclip::Thumbnail.expects(:make).raises(
Paperclip::Errors::CommandNotFoundError
)
end
it "propagates the error" do
assert_raises(Paperclip::Errors::CommandNotFoundError) do
@dummy.avatar = @file
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment