Skip to content


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

merged 1 commit into from

5 participants


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

1 check passed

Details default The Travis build passed

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

pdfkit member

@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
3 lib/pdfkit/pdfkit.rb
@@ -68,7 +68,8 @@ def to_pdf(path=nil)
result = if path
- raise "command failed: #{invoke}" if result.to_s.strip.empty?
+ # $? is thread safe per
+ raise "command failed: #{invoke}" if result.to_s.strip.empty? or !$?.success?
return result
5 spec/pdfkit_spec.rb
@@ -187,6 +187,10 @@
pdfkit.source.to_s.should include("<style>#{}</style></head>")
+ it "should throw an error if it is unable to connect" do
+ pdfkit ="")
+ lambda { pdfkit.to_pdf }.should raise_error
+ end
context "#to_file" do
@@ -232,5 +236,4 @@
File.exist?(@test_path).should be_false
Something went wrong with that request. Please try again.