Error: Added PandocFilterError.

This commit is contained in:
John MacFarlane 2017-04-13 19:24:50 +02:00
parent 306dc624d9
commit d722d93b61
2 changed files with 7 additions and 8 deletions

View file

@ -493,21 +493,17 @@ externalFilter f args' d = liftIO $ do
unless (exists && isExecutable) $ do
mbExe <- findExecutable f'
when (isNothing mbExe) $
E.throwIO $ PandocAppError 83 $
"Error running filter " ++ f ++ ":\n" ++
"Could not find executable '" ++ f' ++ "'."
E.throwIO $ PandocFilterError f ("Could not find executable " ++ f')
env <- getEnvironment
let env' = Just $ ("PANDOC_VERSION", pandocVersion) : env
(exitcode, outbs) <- E.handle filterException $
pipeProcess env' f' args'' $ encode d
case exitcode of
ExitSuccess -> return $ either error id $ eitherDecode' outbs
ExitFailure ec -> E.throwIO $ PandocAppError 83 $
"Error running filter " ++ f ++ "\n" ++
"Filter returned error status " ++ show ec
ExitFailure ec -> E.throwIO $ PandocFilterError f
("Filter returned error status " ++ show ec)
where filterException :: E.SomeException -> IO a
filterException e = E.throwIO $ PandocAppError 83 $
"Error running filter " ++ f ++ "\n" ++ show e
filterException e = E.throwIO $ PandocFilterError f (show e)
-- | Data structure for command line options.
data Opt = Opt

View file

@ -56,6 +56,7 @@ data PandocError = PandocIOError String IOError
| PandocFailOnWarningError
| PandocPDFProgramNotFoundError String
| PandocPDFError String
| PandocFilterError String String
| PandocAppError Int String
deriving (Show, Typeable, Generic)
@ -88,6 +89,8 @@ handleError (Left e) =
PandocPDFProgramNotFoundError pdfprog -> err 47 $
pdfprog ++ " not found. " ++ pdfprog ++ " is needed for pdf output."
PandocPDFError log -> err 43 $ "Error producing PDF.\n" ++ log
PandocFilterError filter msg -> err 83 $ "Error running filter " ++
filter ++ ":\n" ++ msg
PandocAppError ec s -> err ec s
err :: Int -> String -> IO a