Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

No more NotIdentifiedByImageMagick errors if IM is not in the path. G…

…ive a real error.

Based on a commit by Henrik N <henrik@nyh.se>
  • Loading branch information...
commit ecd369df45d0595faeb2dc4b0a1334c4bff34dad 1 parent 44124a5
Jon Yurek jyurek authored
Showing with 23 additions and 2 deletions.
  1. +9 −2 lib/paperclip.rb
  2. +14 −0 test/paperclip_test.rb
11 lib/paperclip.rb
View
@@ -113,6 +113,10 @@ def run cmd, *params
Paperclip.log(command) if Paperclip.options[:log_command]
output = `#{command}`
+
+ if $?.exitstatus == 127
+ raise CommandNotFoundError
+ end
unless expected_outcodes.include?($?.exitstatus)
raise PaperclipCommandLineError,
"Error while running #{cmd}. Expected return code to be #{expected_outcodes.join(", ")} but was #{$?.exitstatus}",
@@ -167,7 +171,7 @@ def logging? #:nodoc:
class PaperclipError < StandardError #:nodoc:
end
- class PaperclipCommandLineError < StandardError #:nodoc:
+ class PaperclipCommandLineError < PaperclipError #:nodoc:
attr_accessor :output
def initialize(msg = nil, output = nil)
super(msg)
@@ -175,9 +179,12 @@ def initialize(msg = nil, output = nil)
end
end
+ class CommandNotFoundError < PaperclipError
+ end
+
class NotIdentifiedByImageMagickError < PaperclipError #:nodoc:
end
-
+
class InfiniteInterpolationError < PaperclipError #:nodoc:
end
14 test/paperclip_test.rb
View
@@ -62,6 +62,20 @@ class PaperclipTest < Test::Unit::TestCase
end
end
+ context "Calling Paperclip.run when the command is not found" do
+ should "tell you the command isn't there" do
+ begin
+ assert_raises(Paperclip::CommandNotFoundError) do
+ `ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found.
+ Paperclip.stubs(:"`").returns("")
+ Paperclip.run("command")
+ end
+ ensure
+ `ruby -e 'exit 0'` # Unstub $?.exitstatus
+ end
+ end
+ end
+
should "prevent dangerous characters in the command via quoting" do
Paperclip.options[:image_magick_path] = nil
Paperclip.options[:command_path] = nil
Please sign in to comment.
Something went wrong with that request. Please try again.