summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-04-15 12:05:58 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-04-15 12:05:58 +0200
commit1fe1c162ac1891fc688e1aef207dd60e18672c06 (patch)
tree22c7ff93c0de8b4e4d82247b2578663cb45af071 /src
parent76b051f7b44f0df850aafe2f57a44f0486b8b282 (diff)
Error: Added PandocCouldNotFindDataFileError.
Use this instead of PandocAppError when appropriate. Removed exit code from PandocAppError, use 1 for all.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/App.hs8
-rw-r--r--src/Text/Pandoc/Error.hs3
-rw-r--r--src/Text/Pandoc/Shared.hs5
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