From ab8b00ea0c2b312d936ff9cfe076a104644e9210 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 18 Jan 2015 21:48:04 -0800 Subject: Custom writer: raise error if loadstring returns an error status. This will make debugging custom scripts much easier. --- src/Text/Pandoc/Writers/Custom.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/Custom.hs b/src/Text/Pandoc/Writers/Custom.hs index 914d61850..3e4c80a53 100644 --- a/src/Text/Pandoc/Writers/Custom.hs +++ b/src/Text/Pandoc/Writers/Custom.hs @@ -42,6 +42,7 @@ import Text.Pandoc.UTF8 (fromString, toString) import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as C8 import Data.Monoid +import Control.Monad (when) import qualified Data.Map as M import Text.Pandoc.Templates @@ -151,7 +152,11 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do luaScript <- C8.unpack `fmap` C8.readFile luaFile lua <- Lua.newstate Lua.openlibs lua - Lua.loadstring lua luaScript "custom" + status <- Lua.loadstring lua luaScript luaFile + -- check for error in lua script (later we'll change the return type + -- to handle this more gracefully): + when (status /= 0) $ + Lua.tostring lua 1 >>= error Lua.call lua 0 0 -- TODO - call hierarchicalize, so we have that info rendered <- docToCustom lua opts doc -- cgit v1.2.3