git.iko.soy/typeable/pandoc
on master help sign in
Custom writer: raise error if loadstring returns an error status.
ab8b00eJohn MacFarlane
src/Text/Pandoc/Writers/Custom.hs+6−1
@@ -42,6 +42,7 @@ import Text.Pandoc.UTF8 (fromString, toString)
42import Data.ByteString (ByteString)
42import Data.ByteString (ByteString)
43import qualified Data.ByteString.Char8 as C8
43import qualified Data.ByteString.Char8 as C8
44import Data.Monoid
44import Data.Monoid
45+import Control.Monad (when)
45import qualified Data.Map as M
46import qualified Data.Map as M
46import Text.Pandoc.Templates
47import Text.Pandoc.Templates
47
48
@@ -151,7 +152,11 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
151 luaScript <- C8.unpack `fmap` C8.readFile luaFile
152 luaScript <- C8.unpack `fmap` C8.readFile luaFile
152 lua <- Lua.newstate
153 lua <- Lua.newstate
153 Lua.openlibs lua
154 Lua.openlibs lua
154− Lua.loadstring lua luaScript "custom"
155+ status <- Lua.loadstring lua luaScript luaFile
156+ -- check for error in lua script (later we'll change the return type
157+ -- to handle this more gracefully):
158+ when (status /= 0) $
159+ Lua.tostring lua 1 >>= error
155 Lua.call lua 0 0
160 Lua.call lua 0 0
156 -- TODO - call hierarchicalize, so we have that info
161 -- TODO - call hierarchicalize, so we have that info
157 rendered <- docToCustom lua opts doc
162 rendered <- docToCustom lua opts doc