Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Name a missing Lua module in the error log
| -rw-r--r-- | custom/extensions/about-render.lua | 6 | |
| -rw-r--r-- | custom/extensions/email-gravatar.lua | 6 | |
| -rw-r--r-- | custom/extensions/email-libravatar.lua | 6 | |
| -rw-r--r-- | custom/extensions/syntax-highlight.lua | 9 | |
| -rw-r--r-- | tests/extensions/test-about-render.lua | 7 | |
| -rw-r--r-- | tests/extensions/test-email-avatar.lua | 6 | |
| -rw-r--r-- | tests/extensions/test-syntax-highlight.lua | 4 | |
| -rwxr-xr-x | tests/t0501-about-render.sh | 3 | |
| -rwxr-xr-x | tests/t0502-syntax-highlight.sh | 5 | |
| -rwxr-xr-x | tests/t0504-email-avatar.sh | 5 |
10 files changed, 47 insertions, 10 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index 35f30d0..e3747ec 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -10,7 +10,8 @@ -- about-filter=lua:/usr/local/lib/cgit/filters/about-render.lua -- Markdown and man pages need lpeg, built for the Lua cgit is linked --- against. Without it both fall back to escaped plain text. +-- against. Without it both fall back to escaped plain text, and the error +-- log says so. -- -- # Debian and Ubuntu -- sudo apt install lua-lpeg @@ -21,6 +22,9 @@ -- # or with LuaRocks, matched to your Lua version -- sudo luarocks --lua-version 5.1 install lpeg local has_lpeg, lpeg = pcall(require, "lpeg") +if not has_lpeg then + io.stderr:write("[cgit] Unable to load lpeg, so markdown and man pages show as plain text\n") +end -- Readmes larger than this are served as escaped plain text rather than diff --git a/custom/extensions/email-gravatar.lua b/custom/extensions/email-gravatar.lua index 467deff..c89da79 100644 --- a/custom/extensions/email-gravatar.lua +++ b/custom/extensions/email-gravatar.lua @@ -13,7 +13,8 @@ -- openssl.digest, from <https://github.com/wahern/luaossl>. The reliable -- cross-platform install is LuaRocks, matched to the Lua version cgit is built -- against, and it needs the OpenSSL development headers present. Without it --- the filter draws no icons and leaves the names as they are. +-- the filter draws no icons, leaving the names as they are, and says so in the +-- error log. -- -- # Debian and Ubuntu -- sudo apt install luarocks libssl-dev @@ -33,6 +34,9 @@ -- SHA-256, the form Gravatar documents. local has_digest, digest = pcall(require, "openssl.digest") +if not has_digest then + io.stderr:write("[cgit] Unable to load openssl.digest, so no avatar icons are drawn\n") +end -- The size is in pixels and serves both as the image asked of the service and diff --git a/custom/extensions/email-libravatar.lua b/custom/extensions/email-libravatar.lua index 0a6e10c..79794a7 100644 --- a/custom/extensions/email-libravatar.lua +++ b/custom/extensions/email-libravatar.lua @@ -12,7 +12,8 @@ -- openssl.digest, from <https://github.com/wahern/luaossl>. The reliable -- cross-platform install is LuaRocks, matched to the Lua version cgit is built -- against, and it needs the OpenSSL development headers present. Without it --- the filter draws no icons and leaves the names as they are. +-- the filter draws no icons, leaving the names as they are, and says so in the +-- error log. -- -- # Debian and Ubuntu -- sudo apt install luarocks libssl-dev @@ -32,6 +33,9 @@ -- SHA-256, which Libravatar accepts alongside MD5. local has_digest, digest = pcall(require, "openssl.digest") +if not has_digest then + io.stderr:write("[cgit] Unable to load openssl.digest, so no avatar icons are drawn\n") +end -- The size is in pixels and serves both as the image asked of the service and diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua index 7414b63..2928250 100644 --- a/custom/extensions/syntax-highlight.lua +++ b/custom/extensions/syntax-highlight.lua @@ -4,8 +4,8 @@ -- Scintillua lexers and reach the page wrapped in span elements carrying the -- hl- classes that assets/cgit.css styles. Whenever a piece is missing or -- will not load, from lpeg down to a single lexer, the filter falls back to --- plain escaped text instead of failing. It runs on Lua 5.1 through 5.5 and --- LuaJIT. +-- plain escaped text instead of failing, and a missing lpeg or Scintillua is +-- noted in the error log. It runs on Lua 5.1 through 5.5 and LuaJIT. -- -- source-filter=lua:/usr/local/lib/cgit/filters/syntax-highlight.lua @@ -140,6 +140,7 @@ end local function load_scintillua() local dir = scintillua_path() if not dir then + io.stderr:write("[cgit] Unable to find the Scintillua lexers, so source is shown uncoloured\n") return nil end package.path = dir .. "/?.lua;" .. package.path @@ -149,6 +150,10 @@ local function load_scintillua() if ok and type(mod) == "table" and type(mod.load) == "function" then return mod end + if not ok then + local reason = tostring(mod):match("[^\n]*") + io.stderr:write("[cgit] Unable to load the Scintillua lexers: " .. reason .. "\n") + end return nil end diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index 95e95bb..45cc5b3 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -24,6 +24,13 @@ end h.load(script) +-- A missing lpeg is written to the error log as the script loads. +if mode == "nolpeg" then + h.contains("a missing lpeg is named in the error log", h.error_log(), "Unable to load lpeg") +elseif has_lpeg then + h.equals("with lpeg the error log stays empty", h.error_log(), "") +end + local function render(filename, text) return h.run({ filename }, { text }) end diff --git a/tests/extensions/test-email-avatar.lua b/tests/extensions/test-email-avatar.lua index 3f14eac..aa021e2 100644 --- a/tests/extensions/test-email-avatar.lua +++ b/tests/extensions/test-email-avatar.lua @@ -26,6 +26,12 @@ end h.load(script) +if mode == "missing" then + h.contains("a missing luaossl is named in the error log", h.error_log(), "Unable to load openssl.digest") +else + h.equals("with luaossl the error log stays empty", h.error_log(), "") +end + local function render(email, name) return h.run({ email, "commit" }, { name }) end diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index a0debc6..8acbf91 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -23,9 +23,12 @@ if mode == "nolexers" then local out, ret = render("hello.fake", "if 42") h.equals("without lexers source is served escaped", out, "if 42") h.equals("close answers zero", ret, 0) + h.contains("and the error log says the lexers would not load", h.error_log(), + "Unable to load the Scintillua lexers") out = render("hello.fake", "a <b> & c") h.equals("the fallback escapes markup", out, "a <b> & c") + h.equals("and the error log hears of it only once", h.error_log(), "") -- Large output leaves in slices, and a byte lost at a boundary would -- put the line numbers beside it out of step, so the whole escaped @@ -48,6 +51,7 @@ if mode == "nolexers" then end local out, ret = render("hello.fake", "if 42 'hi' & zz") +h.equals("loaded lexers leave the error log empty", h.error_log(), "") h.contains("keywords are wrapped in their class", out, "<span class='hl-keyword'>if</span>") h.contains("numbers are wrapped in their class", out, "<span class='hl-number'>42</span>") h.contains("a dotted tag maps by its first component", out, "<span class='hl-string'>'hi'</span>") diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index e4eaf5c..56f2e77 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -119,9 +119,10 @@ test_expect_success CGIT_LUA 'the about page shows plain text as it is' ' ' test_expect_success CGIT_LUA_NOLPEG 'without lpeg the readme is served escaped' ' - cgit_url "md/about/" >tmp && + cgit_url "md/about/" >tmp 2>err && grep "<pre class=.plaintext.>" tmp && grep "# The Title" tmp && + grep "Unable to load lpeg" err && cgit_url "man/about/" >tmp && grep "<pre class=.plaintext.>" tmp && grep ".SH NAME" tmp diff --git a/tests/t0502-syntax-highlight.sh b/tests/t0502-syntax-highlight.sh index 2ca3c9f..dbb7bb0 100755 --- a/tests/t0502-syntax-highlight.sh +++ b/tests/t0502-syntax-highlight.sh @@ -68,9 +68,10 @@ test_expect_success CGIT_LUA 'bytes between tokens reach the page escaped' ' # has to hand the source back escaped instead. test_expect_success CGIT_LUA 'without scintillua the source is served escaped' ' CGIT_SCINTILLUA_PATH=/nonexistent CGIT_CONFIG="$PWD/cgitrc" \ - QUERY_STRING="url=fake/tree/hello.fake" cgit >tmp && + QUERY_STRING="url=fake/tree/hello.fake" cgit >tmp 2>err && grep "if 42 & zz" tmp && - ! grep "hl-keyword" tmp + ! grep "hl-keyword" tmp && + grep "Unable to load the Scintillua lexers" err ' test_expect_success CGIT_LUA 'a lone carriage return reaches the page as an escape' ' diff --git a/tests/t0504-email-avatar.sh b/tests/t0504-email-avatar.sh index 60db6d6..ccda85a 100755 --- a/tests/t0504-email-avatar.sh +++ b/tests/t0504-email-avatar.sh @@ -72,10 +72,11 @@ test_expect_success CGIT_LUA_OSSL 'the commit page draws the author icon' ' ' test_expect_success CGIT_LUA_NOOSSL 'without luaossl the page keeps the name alone' ' - cgit_url "avatar/commit/" >tmp && + cgit_url "avatar/commit/" >tmp 2>err && grep "A U Thor" tmp && ! grep "<img src=.https:" tmp && - ! grep "Unable to complete the request" tmp + ! grep "Unable to complete the request" tmp && + grep "Unable to load openssl.digest" err ' test_done |
