Enable need-check-nil and start the burn down

`Roles.new_role` returned the result of `error`, which made it nullable,
and `set_permission_group` returned nil for an unknown group, which
broke the config chain with an index error rather than saying so.

Positions and bounding boxes read back from the game always use the
named members, so they are narrowed once where they enter a function.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:43 +00:00
co-authored by Claude Opus 5
parent 1868616a4d
commit 3f46055b70
3 changed files with 11 additions and 12 deletions
+2 -3
View File
@@ -719,7 +719,7 @@ local role = Roles.new_role('Moderator', 'Mod')
]]
function Roles.new_role(name, short_hand)
ExpUtil.assert_not_runtime()
if Roles.config.roles[name] then return error("Role name is non unique") end
if Roles.config.roles[name] then error("Role name is non unique") end
local role = setmetatable({
name = name,
short_hand = short_hand or name,
@@ -896,8 +896,7 @@ function Roles._prototype:set_permission_group(name, use_factorio_api)
if use_factorio_api then
self.permission_group = { true, name } --[[@as [boolean, string] ]]
else
local group = Groups.get_group_by_name(name)
if not group then return end
assert(Groups.get_group_by_name(name), "Permission group not found: " .. name)
self.permission_group = name
end
return self