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.
This commit is contained in:
parent
2262f005ce
commit
12f8efe012
3 changed files with 11 additions and 6 deletions
|
@ -792,6 +792,8 @@ end
|
|||
|
||||
--- Runs command with arguments, passing it some input, and returns the output.
|
||||
-- @treturn string Output of command.
|
||||
-- @raise A table containing the keys `command`, `error_code`, and `output` is
|
||||
-- thrown if the command exits with a non-zero error code.
|
||||
-- @usage
|
||||
-- local ec, output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
|
||||
function M.pipe (command, args, input)
|
||||
|
@ -806,9 +808,7 @@ function M.pipe (command, args, input)
|
|||
end
|
||||
}
|
||||
)
|
||||
-- TODO: drop the wrapping call to `tostring` as soon as hslua supports
|
||||
-- non-string error objects.
|
||||
error(tostring(err))
|
||||
error(err)
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
|
|
@ -1132,6 +1132,12 @@ Lua functions for pandoc scripts.
|
|||
|
||||
- Output of command.
|
||||
|
||||
Raises:
|
||||
|
||||
- A table containing the keys `command`, `error_code`, and
|
||||
`output` is thrown if the command exits with a non-zero
|
||||
error code.
|
||||
|
||||
Usage:
|
||||
|
||||
local output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
|
||||
|
|
|
@ -196,9 +196,8 @@ runFilterFunction lf x = do
|
|||
push x
|
||||
z <- Lua.pcall 1 1 Nothing
|
||||
when (z /= OK) $ do
|
||||
msg <- Lua.peek (-1) <* Lua.pop 1
|
||||
let prefix = "Error while running filter function: "
|
||||
Lua.throwLuaError $ prefix ++ msg
|
||||
let addPrefix = ("Error while running filter function: " ++)
|
||||
Lua.throwTopMessageAsError' addPrefix
|
||||
|
||||
elementOrList :: FromLuaStack a => a -> Lua [a]
|
||||
elementOrList x = do
|
||||
|
|
Loading…
Add table
Reference in a new issue