File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -105,9 +105,14 @@ def to_pdf(self, path=None):
105
105
input = None
106
106
stdout , stderr = result .communicate (input = input )
107
107
108
+ exit_code = result .returncode
109
+
108
110
if 'Error' in stderr .decode ('utf-8' ):
109
111
raise IOError ('wkhtmltopdf reported an error:\n ' + stderr .decode ('utf-8' ))
110
112
113
+ if exit_code != 0 :
114
+ raise IOError ("wkhtmltopdf exited with non-zero code {0}. error:\n {1}" .format (exit_code , stderr .decode ("utf-8" )))
115
+
111
116
# Since wkhtmltopdf sends its output to stderr we will capture it
112
117
# and properly send to stdout
113
118
if '--quiet' not in args :
Original file line number Diff line number Diff line change @@ -293,5 +293,14 @@ def test_raise_error_with_wrong_css_path(self):
293
293
with self .assertRaises (IOError ):
294
294
r .to_pdf ()
295
295
296
+ def test_raise_error_if_bad_wkhtmltopdf_option (self ):
297
+ r = pdfkit .PDFKit ('<html><body>Hai!</body></html>' , 'string' ,
298
+ options = {'bad-option' : None })
299
+ with self .assertRaises (IOError ) as cm :
300
+ r .to_pdf ()
301
+
302
+ raised_exception = cm .exception
303
+ self .assertRegexpMatches (str (raised_exception ), '^wkhtmltopdf exited with non-zero code 1. error:\n Unknown long argument --bad-option\n ' )
304
+
296
305
if __name__ == "__main__" :
297
306
unittest .main ()
You can’t perform that action at this time.
0 commit comments