add stricter checking on urls and paths, and make sure that if one

package fails to load other may continue to load
This commit is contained in:
2025-04-25 23:58:33 -05:00
parent dfb1820a8e
commit 2ccbb7ea74
2 changed files with 22 additions and 6 deletions

View File

@ -42,12 +42,10 @@ function M.registertree(speclist, overrides)
disable = over.disable or spec.disable
}
local ok = packager:new(spec, overrides)
-- if erroring print out the spec and the error
if not ok then
error(string.format("(spec=%s)", vim.inspect(spec)))
end
-- While a package can fail to load we just don't care, it will work itself
-- out. The goal is to make sure every plugin that can load does load, not
-- keep working plugins from loading because an unrelated one doesn't load.
packager:new(spec, overrides)
end
end

View File

@ -55,6 +55,17 @@ local root
---@type package[]
local packages = {}
--- check if a string seems to be a url
---@param url string the "url" to check
---@return boolean is_url
local function is_url(url)
if url:sub(1, 8) == "https://" or
url:sub(1, 7) == "http://" then
return true
end
return false
end
--- check a spec to see if it's correct
---@param spec spec|string the specification to check
---@return spec|false spec if the spec is ok or false
@ -117,6 +128,10 @@ local function check_spec(spec)
if type(spec.url) ~= "string" then
logger:log("spec", "spec.url must be a string in %s", spec[1])
return false
elseif not is_url(spec.url) then -- more strict checking on urls
logger:log("spec", "spec.url must be a properly formatted url in %s",
spec[1])
return false
end
end
@ -124,6 +139,9 @@ local function check_spec(spec)
if type(spec.path) ~= "string" then
logger:log("spec", "spec.path must be a string in %s", spec[1])
return false
elseif not vim.fn.isdirectory(spec.path) then
logger:log("spec", "spec.path must be a valid directory in %s", spec[1])
return false
end
end