From d722d93b6118bfed4e0a176a66f859b9636ae689 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Thu, 13 Apr 2017 19:24:50 +0200
Subject: [PATCH] Error: Added PandocFilterError.

---
 src/Text/Pandoc/App.hs   | 12 ++++--------
 src/Text/Pandoc/Error.hs |  3 +++
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index b34980c71..77e13a297 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -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
diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs
index b6782036f..4ead6aba8 100644
--- a/src/Text/Pandoc/Error.hs
+++ b/src/Text/Pandoc/Error.hs
@@ -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