From 53974c1edbf82e5e594bb7ce80b61f7fadd9d76f Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 14:22:30 +0000 Subject: cgit-about-filter: show errors in filter_open and filter_write Errors there are swallowed the same way as in filter_close. Remember the first error and show it when the filter closes. --- .../simple/cgit-about-filter/cgit-about-filter.lua | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'pkgs') 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("
")
         ;(html_txt or io.write)(err)
         emit("
") -- cgit v1.3.1