style(plugins): more descriptive error when a spec module didnt return any specs

This commit is contained in:
Folke Lemaitre 2023-04-22 14:10:06 +02:00
parent 5c89dc52f4
commit dff6f07290
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 12 additions and 1 deletions

View File

@ -268,7 +268,18 @@ function Spec:import(spec)
---@diagnostic disable-next-line: no-unknown ---@diagnostic disable-next-line: no-unknown
package.loaded[modname] = nil package.loaded[modname] = nil
Util.try(function() Util.try(function()
self:normalize(require(modname)) local mod = require(modname)
if type(mod) ~= "table" then
self.importing = nil
return self:error(
"Invalid spec module: `"
.. modname
.. "`\nExpected a `table` of specs, but a `"
.. type(mod)
.. "` was returned instead"
)
end
self:normalize(mod)
self.importing = nil self.importing = nil
Util.track() Util.track()
end, { end, {