aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-18 21:48:04 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-18 21:48:04 -0800
commitab8b00ea0c2b312d936ff9cfe076a104644e9210 (patch)
treeb6513fef44f03996697f84446fd197b32b439b14 /src/Text/Pandoc
parent6e7a76c800ea52a60a7e29bd092b54be1ff79e1c (diff)
downloadpandoc-ab8b00ea0c2b312d936ff9cfe076a104644e9210.tar.gz
Custom writer: raise error if loadstring returns an error status.
This will make debugging custom scripts much easier.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/Custom.hs7
1 files changed, 6 insertions, 1 deletions
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