Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better error reporting from the command line tool
Closes #5
  • Loading branch information
ricn committed Jul 18, 2015
1 parent bd5d5e3 commit 26eec15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/pdf2htmlex.ex
Expand Up @@ -88,10 +88,9 @@ defmodule Pdf2htmlex do
defp exec_cmd(opts) do
cmd = System.find_executable("pdf2htmlEX") || ""
{msg, exit_status} = System.cmd(cmd, opts, stderr_to_stdout: true)
if exit_status == 1 do
raise RuntimeError, message: msg
if exit_status != 0 do
raise RuntimeError, message: "The command line tool reported an error: #{msg}"
end

end

defp i_to_s(s), do: Integer.to_string(s)
Expand Down
Binary file added test/fixtures/word.pdf
Binary file not shown.
11 changes: 9 additions & 2 deletions test/pdf2htmlex_test.exs
Expand Up @@ -5,8 +5,8 @@ defmodule Pdf2htmlexTest do
@simple_pdf Path.join(__DIR__, "fixtures/simple.pdf")
@multi_page_pdf Path.join(__DIR__, "fixtures/multi_page.pdf")
@with_images Path.join(__DIR__, "fixtures/with_images.pdf")
@word_doc Path.join(__DIR__, "fixtures/word.docx")

@word_doc Path.join(__DIR__, "fixtures/word.docx")
@word_doc_with_pdf_ext Path.join(__DIR__, "fixtures/word.pdf")
test "simplest conversion possible" do
tmp_dir = rnd_tmp_dir
open(@simple_pdf) |> convert_to!(tmp_dir)
Expand Down Expand Up @@ -66,6 +66,13 @@ defmodule Pdf2htmlexTest do
end
end

test "try converting a word document with a pdf extension" do
tmp_dir = rnd_tmp_dir
assert_raise RuntimeError, fn ->
open(@word_doc_with_pdf_ext) |> convert_to!(tmp_dir)
end
end

defp rnd_tmp_dir do
dir = System.tmp_dir! <> "/" <> SecureRandom.uuid <> "/"
File.mkdir! dir
Expand Down

0 comments on commit 26eec15

Please sign in to comment.