diff options
-rw-r--r-- | src/Text/Pandoc/App.hs | 8 | ||||
-rw-r--r-- | src/Text/Pandoc/Error.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 5 |
3 files changed, 9 insertions, 7 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index f5194b42d..4b14a9d73 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -175,7 +175,7 @@ convertWithOpts opts = do (\o d -> liftIO $ writeCustom writerName o d) :: Writer PandocIO) else case getWriter writerName of - Left e -> E.throwIO $ PandocAppError 9 $ + Left e -> E.throwIO $ PandocAppError $ if format == "pdf" then e ++ "\nTo create a pdf using pandoc, use " ++ @@ -189,7 +189,7 @@ convertWithOpts opts = do -- the sake of the text2tags reader. reader <- case getReader readerName of Right r -> return (r :: Reader PandocIO) - Left e -> E.throwIO $ PandocAppError 7 e' + Left e -> E.throwIO $ PandocAppError e' where e' = case readerName of "pdf" -> e ++ "\nPandoc can convert to PDF, but not from PDF." @@ -359,7 +359,7 @@ convertWithOpts opts = do istty <- queryTerminal stdOutput #endif when (istty && not (isTextFormat format) && outputFile == "-") $ - E.throwIO $ PandocAppError 5 $ + E.throwIO $ PandocAppError $ "Cannot write " ++ format ++ " output to stdout.\n" ++ "Specify an output file using the -o option." @@ -431,7 +431,7 @@ convertWithOpts opts = do -- make sure writer is latex, beamer, context, html5 or ms unless (laTeXOutput || conTeXtOutput || html5Output || msOutput) $ - liftIO $ E.throwIO $ PandocAppError 47 $ + liftIO $ E.throwIO $ PandocAppError $ "cannot produce pdf output with " ++ format ++ " writer" let pdfprog = case () of diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs index 637db6187..135cb3945 100644 --- a/src/Text/Pandoc/Error.hs +++ b/src/Text/Pandoc/Error.hs @@ -57,6 +57,7 @@ data PandocError = PandocIOError String IOError | PandocPDFProgramNotFoundError String | PandocPDFError String | PandocFilterError String String + | PandocCouldNotFindDataFileError String | PandocAppError String deriving (Show, Typeable, Generic) @@ -91,6 +92,8 @@ handleError (Left e) = PandocPDFError logmsg -> err 43 $ "Error producing PDF.\n" ++ logmsg PandocFilterError filtername msg -> err 83 $ "Error running filter " ++ filtername ++ ":\n" ++ msg + PandocCouldNotFindDataFileError fn -> err 97 $ + "Could not find data file " ++ fn PandocAppError s -> err 1 s err :: Int -> String -> IO a diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index dfdbaf428..8256d14c0 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -674,8 +674,7 @@ readDefaultDataFile "reference.odt" = readDefaultDataFile fname = #ifdef EMBED_DATA_FILES case lookup (makeCanonical fname) dataFiles of - Nothing -> E.throwIO $ PandocAppError 97 $ - "Could not find data file " ++ fname + Nothing -> E.throwIO $ PandocCouldNotFindDataFileError fname Just contents -> return contents where makeCanonical = Posix.joinPath . transformPathParts . splitDirectories transformPathParts = reverse . foldl go [] @@ -691,7 +690,7 @@ checkExistence fn = do exists <- doesFileExist fn if exists then return fn - else E.throwIO $ PandocAppError 97 ("Could not find data file " ++ fn) + else E.throwIO $ PandocCouldNotFindDataFileError fn #endif -- | Read file from specified user data directory or, if not found there, from |