diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-07-02 12:28:46 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-07-02 12:28:46 -0700 |
commit | 5f0b87556573adaf979f3c2c529f81270aaa18ec (patch) | |
tree | c1f7a949506587f986d3d67d0ccd7bdb37e02617 | |
parent | 904422953143270bcb9cf30c787df36bc9c4f52e (diff) | |
download | pandoc-5f0b87556573adaf979f3c2c529f81270aaa18ec.tar.gz |
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.
-rw-r--r-- | pandoc.hs | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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 |