From 3bc09f75dec9c0e868c950406065f40752e459d7 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 11 Oct 2023 17:05:56 +0300 Subject: [PATCH 1/2] chore(cli): Drop warnings from resolveFile(), nil means it didn't resolve anything --- core/sile.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sile.lua b/core/sile.lua index 9579c6122..fdc22a591 100644 --- a/core/sile.lua +++ b/core/sile.lua @@ -393,8 +393,8 @@ function SILE.resolveFile (filename, pathprefix) local resolved, err = package.searchpath(filename, path, "/") if resolved then if SILE.makeDeps then SILE.makeDeps:add(resolved) end - else - SU.warn(("Unable to find file '%s': %s"):format(filename, err)) + elseif SU.debugging("paths") then + SU.debug("paths", ("Unable to find file '%s': %s"):format(filename, err)) end return resolved end From ff18bbce46b0a448325e8040d404d77996355a83 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 11 Oct 2023 18:04:26 +0300 Subject: [PATCH 2/2] chore(core): Protect all calls to resolveFile() with proper errors --- core/sile.lua | 5 +---- packages/bibtex/init.lua | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/sile.lua b/core/sile.lua index fdc22a591..33b5459b3 100644 --- a/core/sile.lua +++ b/core/sile.lua @@ -330,10 +330,7 @@ function SILE.processFile (filename, format, options) if SILE.masterDir and SILE.masterDir:len() >= 1 then _G.extendSilePath(SILE.masterDir) end - filename = SILE.resolveFile(filename) - if not filename then - SU.error("Could not find file") - end + filename = SILE.resolveFile(filename) or SU.error("Could not find file") local mode = lfs.attributes(filename).mode if mode ~= "file" and mode ~= "named pipe" then SU.error(filename.." isn't a file or named pipe, it's a ".. mode .."!") diff --git a/packages/bibtex/init.lua b/packages/bibtex/init.lua index 584f97223..134ee3301 100644 --- a/packages/bibtex/init.lua +++ b/packages/bibtex/init.lua @@ -39,12 +39,12 @@ end) ---@diagnostic enable: undefined-global, unused-local, lowercase-global local parseBibtex = function (fn) - fn = SILE.resolveFile(fn) - local fh,e = io.open(fn) - if e then SU.error("Error reading bibliography file "..e) end + fn = SILE.resolveFile(fn) or SU.error("Unable to resolve Bibtex file "..fn) + local fh, e = io.open(fn) + if e then SU.error("Error reading bibliography file: "..e) end local doc = fh:read("*all") local t = epnf.parsestring(bibtexparser, doc) - if not(t) or not(t[1]) or t.id ~= "document" then + if not t or not t[1] or t.id ~= "document" then SU.error("Error parsing bibtex") end local entries = {}