Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/pixelpress/renderers/weasyprint_renderer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
class Pixelpress::WeasyPrintRenderer
class WeasyPrintInstallationError < StandardError; end
class WeasyPrintExecutionError < StandardError; end

def render(input)
output = Tempfile.new

system executable_path, "--encoding", "utf-8", input.path, output.path, exception: true
success = system(executable_path, "--encoding", "utf-8", input.path, output.path)

unless success
raise WeasyPrintExecutionError.new("WeasyPrint execution failed with exit code #{$?.exitstatus}")
end

return output
end

Expand Down
12 changes: 12 additions & 0 deletions spec/renderers/weasyprint_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@
}.to raise_error(/Unable to locate weasyprint/)
end
end

context "when weasyprint exits with non-zero exit code" do
it "reraises a reasonable error" do
expect(renderer).to receive(:system) do
Kernel.system("exit 1")
end

expect {
renderer.render(input)
}.to raise_error(Pixelpress::WeasyPrintRenderer::WeasyPrintExecutionError, "WeasyPrint execution failed with exit code 1")
end
end
end
Loading