PDF: Better error message.

This commit is contained in:
John MacFarlane 2012-01-20 19:52:56 -08:00
parent ce3653e39d
commit b4a6c02343
2 changed files with 8 additions and 5 deletions
src
Text/Pandoc
pandoc.hs

View file

@ -56,10 +56,11 @@ tex2pdf' :: FilePath -- ^ temp directory for output
-> IO (Either ByteString ByteString) -> IO (Either ByteString ByteString)
tex2pdf' tmpDir program source = do tex2pdf' tmpDir program source = do
(exit, log', mbPdf) <- runTeXProgram program 3 tmpDir source (exit, log', mbPdf) <- runTeXProgram program 3 tmpDir source
let msg = "Error producing PDF from TeX source."
case (exit, mbPdf) of case (exit, mbPdf) of
(ExitFailure _, _) -> return $ Left $ extractMsg log' (ExitFailure _, _) -> return $ Left $
(ExitSuccess, Nothing) -> return $ Left msg <> "\n" <> extractMsg log'
"tex2pdf: ExitSuccess but no PDF created!" (ExitSuccess, Nothing) -> return $ Left msg
(ExitSuccess, Just pdf) -> return $ Right pdf (ExitSuccess, Just pdf) -> return $ Right pdf
data TeXProgram = PDFLaTeX data TeXProgram = PDFLaTeX
@ -70,6 +71,9 @@ data TeXProgram = PDFLaTeX
| PDFTeX | PDFTeX
deriving (Show, Read) deriving (Show, Read)
(<>) :: ByteString -> ByteString -> ByteString
(<>) = B.append
-- parsing output -- parsing output
extractMsg :: ByteString -> ByteString extractMsg :: ByteString -> ByteString

View file

@ -975,10 +975,9 @@ main = do
do res <- tex2pdf PDFLaTeX $ writeLaTeX writerOptions doc2 do res <- tex2pdf PDFLaTeX $ writeLaTeX writerOptions doc2
case res of case res of
Right pdf -> writeBinary pdf Right pdf -> writeBinary pdf
Left err' -> B.hPutStr stderr err' >> B.hPutStr stderr nl Left err' -> B.hPutStr stderr err'
| otherwise -> error $ "Unknown writer: " ++ writerName' | otherwise -> error $ "Unknown writer: " ++ writerName'
where writeBinary = B.writeFile (encodeString outputFile) where writeBinary = B.writeFile (encodeString outputFile)
nl = B.singleton 10
Just r -> writerFn outputFile =<< postProcess result Just r -> writerFn outputFile =<< postProcess result
where writerFn "-" = UTF8.putStr where writerFn "-" = UTF8.putStr
writerFn f = UTF8.writeFile f writerFn f = UTF8.writeFile f