Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise exception on all pdf generation errors #751

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

thomasbarton
Copy link
Contributor

@thomasbarton thomasbarton commented Jul 9, 2018

Issue: When image assets fail to download from the web (return non 200 statuses). We want to throw an exception.

Passing extra: '--load-media-error-handling abort' to WickedPdf should fail the pdf generation. But it doesnt. This seems to be because the underlying library wkhtmltopdf doesnt return the correct exit code it only returns error output.

Solution: enable a flag in wicked_pdf that will raise an exception if there is any output to stderr.

raise_on_all_errors: true

@unixmonkey unixmonkey merged commit 0cea2ff into mileszs:master Jul 10, 2018
@unixmonkey
Copy link
Collaborator

Great idea. Thanks!

@thomasbarton
Copy link
Contributor Author

Thank you for the quick merge @unixmonkey 👍

When does wicked_pdf plan on releasing a new version of the gem?

@thomasbarton thomasbarton deleted the raise_on_all_errors branch July 10, 2018 17:21
@ximus
Copy link

ximus commented Mar 19, 2019

am I crazy or does wkhtmltopdf (0.12.5) always output via stderr? even when there is no error:

>wkhtmltopdf --page-size Letter file:////foo.html bar.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

status code is 0 and pdf is generated correctly

> wkhtmltopdf --page-size Letter file:////foo.html bar.pdf > out 2>error
> cat out
> cat error
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

@joshuapinter
Copy link
Contributor

joshuapinter commented Apr 23, 2020

am I crazy or does wkhtmltopdf (0.12.5) always output via stderr? even when there is no error:

>wkhtmltopdf --page-size Letter file:////foo.html bar.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

status code is 0 and pdf is generated correctly

> wkhtmltopdf --page-size Letter file:////foo.html bar.pdf > out 2>error
> cat out
> cat error
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

I think you're right. I'm on wkthmltopdf 0.12.3 and stderr gets used for "Loading pages", "Counting pages", etc. That makes setting raise_on_all_errors: true useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants