Do not unlink HTML temp files immediately. #950
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The reason for not wanting to unlink them is primariily for debugging. If an error occurs, the
wkhtmltopdf
command that had problems is shown as part of the error message. Something like this:However, the references to the HTML temp files used in that command are no longer there so it's very difficult to reproduce or investigate further.
We want to keep these files around so that you can essentially run the nearly identical
wkhtmltopdf
command when there was an error and dig deeper into it.Keeping these files does not keep them forever. They are, afterall, temp files and will be cleaned up automatically by the system.
To accomplish this, we use
.close
instead of.close!
, which does not unlink the file immediately after closing it.NOTE: We still want to use
.close!
on the generated PDF files for two reasons:This generated PDF file is not important when an error has occurred and you are re-running the
wkhtmltopdf
command.The generated PDF file is the largest of the files. Typically, the HTML files for header, footer and body are relatively small compared to the generated PDF file.
Fixes #948.