lib/imgkit/imgkit.rb in imgkit-1.0.1 vs lib/imgkit/imgkit.rb in imgkit-1.0.2
- old
+ new
@@ -11,10 +11,19 @@
class ImproperSourceError < StandardError
def initialize(msg)
super("Improper Source: #{msg}")
end
end
+
+ class CommandFailedError < RuntimeError
+ attr_reader :command, :stderr
+ def initialize(command, stderr)
+ @command = command
+ @stderr = stderr
+ super("Command failed: #{command}: #{stderr}")
+ end
+ end
attr_accessor :source, :stylesheets
attr_reader :options
def initialize(url_file_or_html, options = {})
@@ -65,18 +74,20 @@
result = image.gets(nil)
image.close_read
=end
result = nil
+ stderr_output = nil
Open3.popen3(*command) do |stdin,stdout,stderr|
stdin << (@source.to_s) if @source.html?
stdin.close
result = stdout.gets(nil)
+ stderr_output = stderr.readlines.join
stdout.close
stderr.close
end
- raise "command failed: #{command.join(' ')}" unless result
+ raise CommandFailedError.new(command.join(' '), stderr_output) unless result
return result
end
def to_file(path)
File.open(path,'w') {|file| file << self.to_img}