Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Check wkhtmltopdf exit status for success, instead of just looking at output #154

Merged
merged 1 commit into from

5 participants

@swieton

This patch updates PDFKit to check the exit status code from wkhtmltopdf. This way, if you expected the page load to be a success and it was not, you can detect it.

@devn devn merged commit aa0700f into pdfkit:master
@igorkasyanchuk

I've a question about this code change.
I'm faced with issue on production with Passenger 4.0.10 that "!$?.success?" returns false so exception is happen, but PDF is generated. So with commented code "or !$?.success?" everything works well

@sigmavirus24

@golem131 what are you '+1'ing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2012
  1. @swieton
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +2 −1  lib/pdfkit/pdfkit.rb
  2. +4 −1 spec/pdfkit_spec.rb
View
3  lib/pdfkit/pdfkit.rb
@@ -68,7 +68,8 @@ def to_pdf(path=nil)
end
result = File.read(path) if path
- raise "command failed: #{invoke}" if result.to_s.strip.empty?
+ # $? is thread safe per http://stackoverflow.com/questions/2164887/thread-safe-external-process-in-ruby-plus-checking-exitstatus
+ raise "command failed: #{invoke}" if result.to_s.strip.empty? or !$?.success?
return result
end
View
5 spec/pdfkit_spec.rb
@@ -187,6 +187,10 @@
pdfkit.source.to_s.should include("<style>#{File.read(css)}</style></head>")
end
+ it "should throw an error if it is unable to connect" do
+ pdfkit = PDFKit.new("http://google.com/this-should-not-be-found/404.html")
+ lambda { pdfkit.to_pdf }.should raise_error
+ end
end
context "#to_file" do
@@ -232,5 +236,4 @@
File.exist?(@test_path).should be_false
end
end
-
end
Something went wrong with that request. Please try again.