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

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