summaryrefslogtreecommitdiff
path: root/pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-07-02 12:28:46 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-07-02 12:28:46 -0700
commit5f0b87556573adaf979f3c2c529f81270aaa18ec (patch)
treec1f7a949506587f986d3d67d0ccd7bdb37e02617 /pandoc.hs
parent904422953143270bcb9cf30c787df36bc9c4f52e (diff)
Better error messages for filters:
- Inform user if filter requires an interpreter that isn't found in the path. - Inform user if filter returns an error status.
Diffstat (limited to 'pandoc.hs')
-rw-r--r--pandoc.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/pandoc.hs b/pandoc.hs
index df50d01d0..5d201ce36 100644
--- a/pandoc.hs
+++ b/pandoc.hs
@@ -58,7 +58,7 @@ import qualified Control.Exception as E
import Control.Exception.Extensible ( throwIO )
import qualified Text.Pandoc.UTF8 as UTF8
import Control.Monad (when, unless, (>=>))
-import Data.Maybe (fromMaybe)
+import Data.Maybe (fromMaybe, isNothing)
import Data.Foldable (foldrM)
import Network.URI (parseURI, isURI, URI(..))
import qualified Data.ByteString.Lazy as B
@@ -142,12 +142,18 @@ externalFilter f args' d = do
".php" -> ("php", f:args')
_ -> (f, args')
else err 85 $ "Filter " ++ f ++ " not found"
+ when (f' /= f) $ do
+ mbExe <- findExecutable f'
+ when (isNothing mbExe) $
+ err 83 $ "Error running filter " ++ f ++ "\n" ++
+ show f' ++ " not found in path."
(exitcode, outbs, errbs) <- E.handle filterException $
pipeProcess Nothing f' args'' $ encode d
when (not $ B.null errbs) $ B.hPutStr stderr errbs
case exitcode of
ExitSuccess -> return $ either error id $ eitherDecode' outbs
- ExitFailure _ -> err 83 $ "Error running filter " ++ f
+ ExitFailure ec -> err 83 $ "Error running filter " ++ f ++ "\n" ++
+ "Filter returned error status " ++ show ec
where filterException :: E.SomeException -> IO a
filterException e = err 83 $ "Error running filter " ++ f ++ "\n" ++
show e