Configuration/schema: Fix handling of failed checks

This commit is contained in:
Lars Mueller 2021-03-31 23:41:42 +02:00
parent 98bd1741ad
commit 76a17be124
2 changed files with 4 additions and 4 deletions

@ -55,6 +55,7 @@ function configuration(modname)
modname = modname or minetest.get_current_modname()
local schema = modlib.schema.new(assert(include(modname, "schema.lua")))
schema.name = schema.name or modname
local settingtypes = schema:generate_settingtypes()
assert(schema.type == "table")
local overrides = {}
local conf
@ -105,7 +106,7 @@ function configuration(modname)
overrides = modlib.table.deep_add_all(overrides, minetest_conf)
conf = schema:load(overrides, {convert_strings = true, error_message = true})
end
modlib.file.ensure_content(get_resource(modname, "settingtypes.txt"), schema:generate_settingtypes())
modlib.file.ensure_content(get_resource(modname, "settingtypes.txt"), settingtypes)
local readme_path = get_resource(modname, "Readme.md")
local readme = modlib.file.read(readme_path)
if readme then

@ -196,7 +196,7 @@ function load(self, override, params)
push(">=", "min")
push("<", "max_exclusive")
push("<=", "max")
return "out of range: expected value " .. table.concat(conditions, "and")
return "out of range: expected value" .. table.concat(conditions, " and")
end
if typ == "int" then
return "expected integer"
@ -226,8 +226,7 @@ function load(self, override, params)
local function error(type, ...)
if params.error_message then
local formatted = format_error(type, ...)
settingtypes(self)
_error("Invalid value: " .. self.name .. ": " .. formatted)
_error("Invalid value: " .. (self.name and (self.name .. ": ") or "") .. formatted)
end
_error{
type = type,