aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-08-15 21:17:20 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-15 21:17:20 -0700
commitf8b6a224aec780785baf3112f24c44f6c424e6ba (patch)
tree734dafad19e1386f3338c7be95e8b9f7d95340ee /src
parent97fe6c35b5c8c5e3e076f712e841f1db13c5a0bd (diff)
downloadpandoc-f8b6a224aec780785baf3112f24c44f6c424e6ba.tar.gz
Remove initial check for pdf creating program.
Instead, just try running it and raise the exception if it isn't found at that point. This improves things for users of Cygwin on Windows, where the executable won't be found by `findExecutable` unless `.exe` is added. The same exception is raised as before, but at a later point. Closes #3819.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/App.hs4
-rw-r--r--src/Text/Pandoc/PDF.hs32
2 files changed, 27 insertions, 9 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 938bb91e0..521f5e275 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -485,10 +485,6 @@ convertWithOpts opts = do
| html5Output -> "wkhtmltopdf"
| msOutput -> "pdfroff"
| otherwise -> optLaTeXEngine opts
- -- check for pdf creating program
- mbPdfProg <- liftIO $ findExecutable pdfprog
- when (isNothing mbPdfProg) $ liftIO $ E.throwIO $
- PandocPDFProgramNotFoundError pdfprog
res <- makePDF pdfprog f writerOptions verbosity media doc
case res of
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index ef6a4099c..65d546482 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -50,7 +50,9 @@ import System.Exit (ExitCode (..))
import System.FilePath
import System.IO (stdout)
import System.IO.Temp (withTempDirectory, withTempFile)
+import System.IO.Error (IOError, isDoesNotExistError)
import Text.Pandoc.Definition
+import Text.Pandoc.Error (PandocError(PandocPDFProgramNotFoundError))
import Text.Pandoc.MediaBag
import Text.Pandoc.MIME (getMimeType)
import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
@@ -193,7 +195,12 @@ tex2pdf' verbosity args tmpDir program source = do
let numruns = if "\\tableofcontents" `T.isInfixOf` source
then 3 -- to get page numbers
else 2 -- 1 run won't give you PDF bookmarks
- (exit, log', mbPdf) <- runTeXProgram verbosity program args 1 numruns tmpDir source
+ (exit, log', mbPdf) <- E.catch
+ (runTeXProgram verbosity program args 1 numruns tmpDir source)
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError program
+ else E.throwIO e)
case (exit, mbPdf) of
(ExitFailure _, _) -> do
let logmsg = extractMsg log'
@@ -321,8 +328,13 @@ ms2pdf verbosity args source = do
putStrLn $ "[makePDF] Contents:\n"
putStr $ T.unpack source
putStr "\n"
- (exit, out) <- pipeProcess (Just env') "pdfroff" args
- (BL.fromStrict $ UTF8.fromText source)
+ (exit, out) <- E.catch
+ (pipeProcess (Just env') "pdfroff" args
+ (BL.fromStrict $ UTF8.fromText source))
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError "pdfroff"
+ else E.throwIO e)
when (verbosity >= INFO) $ do
BL.hPutStr stdout out
putStr "\n"
@@ -350,7 +362,12 @@ html2pdf verbosity args source = do
putStrLn $ "[makePDF] Contents of " ++ file ++ ":"
BL.readFile file >>= BL.putStr
putStr "\n"
- (exit, out) <- pipeProcess (Just env') "wkhtmltopdf" programArgs BL.empty
+ (exit, out) <- E.catch
+ (pipeProcess (Just env') "wkhtmltopdf" programArgs BL.empty)
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError "wkhtml2pdf"
+ else E.throwIO e)
removeFile file
when (verbosity >= INFO) $ do
BL.hPutStr stdout out
@@ -397,7 +414,12 @@ context2pdf verbosity tmpDir source = inDirectory tmpDir $ do
putStrLn $ "[makePDF] Contents of " ++ file ++ ":"
BL.readFile file >>= BL.putStr
putStr "\n"
- (exit, out) <- pipeProcess (Just env') "context" programArgs BL.empty
+ (exit, out) <- E.catch
+ (pipeProcess (Just env') "context" programArgs BL.empty)
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError "context"
+ else E.throwIO e)
when (verbosity >= INFO) $ do
BL.hPutStr stdout out
putStr "\n"