Improve ABM and LBM registration error handling (#12969)

This commit is contained in:
Jude Melton-Houghton 2022-11-20 15:26:54 -05:00 committed by GitHub
parent 7bf64fc61a
commit 475005012a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -79,8 +79,22 @@ local function check_modname_prefix(name)
end
end
local function check_node_list(list, field)
local t = type(list)
if t == "table" then
for _, entry in pairs(list) do
assert(type(entry) == "string",
"Field '" .. field .. "' contains non-string entry")
end
elseif t ~= "string" and t ~= "nil" then
error("Field '" .. field .. "' has invalid type " .. t)
end
end
function core.register_abm(spec)
-- Add to core.registered_abms
check_node_list(spec.nodenames, "nodenames")
check_node_list(spec.neighbors, "neighbors")
assert(type(spec.action) == "function", "Required field 'action' of type function")
core.registered_abms[#core.registered_abms + 1] = spec
spec.mod_origin = core.get_current_modname() or "??"
@ -89,6 +103,7 @@ end
function core.register_lbm(spec)
-- Add to core.registered_lbms
check_modname_prefix(spec.name)
check_node_list(spec.nodenames, "nodenames")
assert(type(spec.action) == "function", "Required field 'action' of type function")
core.registered_lbms[#core.registered_lbms + 1] = spec
spec.mod_origin = core.get_current_modname() or "??"