Commit b4369301 by Jon Yurek

Make command line error handling more generic

parent 1d22cdca
...@@ -52,7 +52,8 @@ module Paperclip ...@@ -52,7 +52,8 @@ module Paperclip
type = begin type = begin
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist. # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
Paperclip.run("file", "-b --mime :file", :file => @filename) Paperclip.run("file", "-b --mime :file", :file => @filename)
rescue Cocaine::CommandNotFoundError => e rescue Cocaine::CommandLineError => e
Paperclip.log("Error while determining content type: #{e}")
SENSIBLE_DEFAULT SENSIBLE_DEFAULT
end end
......
...@@ -31,16 +31,8 @@ class ContentTypeDetectorTest < Test::Unit::TestCase ...@@ -31,16 +31,8 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
end end
should 'let errors raise if something blows up' do
Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
@filename = "/path/to/something"
assert_raises(Cocaine::CommandLineError) do
Paperclip::ContentTypeDetector.new(@filename).detect
end
end
should 'return a sensible default when the file command is missing' do should 'return a sensible default when the file command is missing' do
Paperclip.stubs(:run).raises(Cocaine::CommandNotFoundError.new) Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
@filename = "/path/to/something" @filename = "/path/to/something"
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
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