summaryrefslogtreecommitdiffstats
path: root/pkgs/simple
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/simple')
-rw-r--r--pkgs/simple/cgit-about-filter/cgit-about-filter.lua28
1 files changed, 24 insertions, 4 deletions
diff --git a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
index 3bbbbcf..d0b820e 100644
--- a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
+++ b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
@@ -281,7 +281,7 @@ local should_render = true
local current_dir = "" -- Stores the directory prefix of the file being processed
local current_file = ""
-function filter_open(...)
+local function open(...)
local args = {...}
current_file = args[1] or ""
@@ -306,7 +306,7 @@ function filter_open(...)
buffer = ""
end
-function filter_write(str)
+local function write(str)
if should_render then
buffer = buffer .. str
end
@@ -390,9 +390,29 @@ end
-- cgit hooks its output into the filter while the filter is open, so the
-- error page of a Lua error in here would end up in the buffer, and the
-- response would end without a word. Show the error instead.
+local err
+
+local function try(f, ...)
+ if not err then
+ local ok, e = xpcall(f, debug.traceback, ...)
+ if not ok then
+ err = e
+ end
+ end
+end
+
+function filter_open(...)
+ err = nil
+ try(open, ...)
+end
+
+function filter_write(str)
+ try(write, str)
+end
+
function filter_close()
- local ok, err = xpcall(close, debug.traceback)
- if not ok then
+ try(close)
+ if err then
emit("<pre>")
;(html_txt or io.write)(err)
emit("</pre>")