git.iko.soy/typeable/pandoc
on master help sign in
pandoc.lua: throw better error when pipe command fails

A table containing the error code, command, and command output is thrown instead of just a string error message.

commit12f8efe0128ade1bd6497a59508f6bd836eb3788 authorAlbert Krewinkel <albert@zeitkraut.de> dateThu 5 Oct 2017, 11:41 (9 years ago) parent2262f00
3 files changed+11−6
data/pandoc.lua+3−3 doc/lua-filters.md+6 src/Text/Pandoc/Lua.hs+2−3
data/pandoc.lua+3−3
@@ -792,6 +792,8 @@ end
792792
793793--- Runs command with arguments, passing it some input, and returns the output.
794794-- @treturn string Output of command.
795+-- @raise A table containing the keys `command`, `error_code`, and `output` is
796+-- thrown if the command exits with a non-zero error code.
795797-- @usage
796798-- local ec, output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
797799function M.pipe (command, args, input)
@@ -806,9 +808,7 @@ function M.pipe (command, args, input)
806808 end
807809 }
808810 )
809− -- TODO: drop the wrapping call to `tostring` as soon as hslua supports
810− -- non-string error objects.
811− error(tostring(err))
811+ error(err)
812812 end
813813 return output
814814end
doc/lua-filters.md+6
@@ -1132,6 +1132,12 @@ Lua functions for pandoc scripts.
11321132
11331133 - Output of command.
11341134
1135+ Raises:
1136+
1137+ - A table containing the keys `command`, `error_code`, and
1138+ `output` is thrown if the command exits with a non-zero
1139+ error code.
1140+
11351141 Usage:
11361142
11371143 local output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
src/Text/Pandoc/Lua.hs+2−3
@@ -196,9 +196,8 @@ runFilterFunction lf x = do
196196 push x
197197 z <- Lua.pcall 1 1 Nothing
198198 when (z /= OK) $ do
199− msg <- Lua.peek (-1) <* Lua.pop 1
200− let prefix = "Error while running filter function: "
201− Lua.throwLuaError $ prefix ++ msg
199+ let addPrefix = ("Error while running filter function: " ++)
200+ Lua.throwTopMessageAsError' addPrefix
202201
203202elementOrList :: FromLuaStack a => a -> Lua [a]
204203elementOrList x = do