summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/App.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-20 16:09:33 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-20 16:19:59 +0200
commitb78afbd9803c75fcf2db32b4ce4ded1b8fa0224a (patch)
tree93a1542b71c908f3995ccc0debaebaa38b800446 /src/Text/Pandoc/App.hs
parent21925284244bb88f927c287c21b48df35234b260 (diff)
Text.Pandoc.Lua: throw LuaException instead of using 'error'.
Text.Pandoc.App: trap LuaException and issue a PandocFilterError.
Diffstat (limited to 'src/Text/Pandoc/App.hs')
-rw-r--r--src/Text/Pandoc/App.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 2c5e1de6b..9778911ba 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -78,7 +78,7 @@ import Text.Pandoc.Builder (setMeta)
import Text.Pandoc.Class (PandocIO, extractMedia, fillMediaBag, getLog,
setResourcePath, withMediaBag, setTrace)
import Text.Pandoc.Highlighting (highlightingStyles)
-import Text.Pandoc.Lua (runLuaFilter)
+import Text.Pandoc.Lua (runLuaFilter, LuaException(..))
import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
import Text.Pandoc.PDF (makePDF)
import Text.Pandoc.Process (pipeProcess)
@@ -782,10 +782,16 @@ expandFilterPath mbDatadir fp = liftIO $ do
_ -> return fp
applyLuaFilters :: MonadIO m
- => Maybe FilePath -> [FilePath] -> [String] -> Pandoc -> m Pandoc
+ => Maybe FilePath -> [FilePath] -> [String] -> Pandoc
+ -> m Pandoc
applyLuaFilters mbDatadir filters args d = do
expandedFilters <- mapM (expandFilterPath mbDatadir) filters
- foldrM ($) d $ map (flip runLuaFilter args) expandedFilters
+ let go f d' = liftIO $ do
+ res <- E.try (runLuaFilter f args d')
+ case res of
+ Right x -> return x
+ Left (LuaException s) -> E.throw (PandocFilterError f s)
+ foldrM ($) d $ map go expandedFilters
applyFilters :: MonadIO m
=> Maybe FilePath -> [FilePath] -> [String] -> Pandoc -> m Pandoc