diff options
| author | tv <tv@krebsco.de> | 2026-11-17 14:22:30 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 15:23:32 +0100 |
| commit | 53974c1edbf82e5e594bb7ce80b61f7fadd9d76f (patch) | |
| tree | 95844a285ecba43924ab8052a2f51f678aac0869 | |
| parent | 9d78b7f285362174e7540c4c035a62ba58d742df (diff) | |
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.
| -rw-r--r-- | pkgs/simple/cgit-about-filter/cgit-about-filter.lua | 28 |
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>") |
