From 300196bc76e8709e3f8c3cf69a6213ba2ffc9e15 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 7 Aug 2026 11:14:51 +0000 Subject: [PATCH] Assert the remaining optional reads in exp_util and commands Co-Authored-By: Claude Opus 5 (1M context) --- exp_commands/module/commands/authorities.lua | 4 ++-- exp_scenario/module/commands/kill.lua | 2 +- exp_util/module/module_exports.lua | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/exp_commands/module/commands/authorities.lua b/exp_commands/module/commands/authorities.lua index 0001b16d..c1ec3309 100644 --- a/exp_commands/module/commands/authorities.lua +++ b/exp_commands/module/commands/authorities.lua @@ -28,13 +28,13 @@ end) --- Allow a player access to system commands, use for debug purposes only --- @param player_name string? The name of the player to give access to, default is the current player function Commands.unlock_system_commands(player_name) - system_players[player_name or game.player.name] = true + system_players[player_name or assert(game.player).name] = true end --- Remove access from system commands for a player, use for debug purposes only --- @param player_name string? The name of the player to give access to, default is the current player function Commands.lock_system_commands(player_name) - system_players[player_name or game.player.name] = nil + system_players[player_name or assert(game.player).name] = nil end --- Get a list of all players who have system commands unlocked diff --git a/exp_scenario/module/commands/kill.lua b/exp_scenario/module/commands/kill.lua index 17d291fd..a71528ed 100644 --- a/exp_scenario/module/commands/kill.lua +++ b/exp_scenario/module/commands/kill.lua @@ -25,7 +25,7 @@ Commands.new("kill", { "exp-commands_kill.description" }) if script.active_mods["space-age"] then other_player.surface.create_entity{ name = "lightning", position = { other_player.position.x, other_player.position.y - 16 }, target = other_player.character } end - other_player.character.die() + assert(other_player.character).die() else return Commands.status.unauthorised{ "exp-commands_kill.lower-role" } end diff --git a/exp_util/module/module_exports.lua b/exp_util/module/module_exports.lua index 5203d97e..98f49a43 100644 --- a/exp_util/module/module_exports.lua +++ b/exp_util/module/module_exports.lua @@ -319,15 +319,15 @@ function ExpUtil.extract_time_units(ticks, units) -- Remove units that are not requested if not units.days then - rtn.hours = rtn.hours + rtn.days * 24 + rtn.hours = assert(rtn.hours) + assert(rtn.days) * 24 rtn.days = nil end if not units.hours then - rtn.minutes = rtn.minutes + rtn.hours * 60 + rtn.minutes = assert(rtn.minutes) + assert(rtn.hours) * 60 rtn.hours = nil end if not units.minutes then - rtn.seconds = rtn.seconds + rtn.minutes * 60 + rtn.seconds = assert(rtn.seconds) + assert(rtn.minutes) * 60 rtn.minutes = nil end if not units.seconds then @@ -487,7 +487,7 @@ function ExpUtil.get_storage_for_stack(options) -- Find a valid entity from the search results local current, count, entities = cache.current, cache.count, cache.entities for i = 1, cache.count do - local entity = entities[((current + i - 1) % count) + 1] + local entity = assert(entities[((current + i - 1) % count) + 1]) if entity.can_insert(item) then cache.current = current + 1 return entity @@ -551,7 +551,7 @@ function ExpUtil.move_items_to_surface(options) options.item = item entity = ExpUtil.get_storage_for_stack(options) entity.insert(options.item) - options.item.clear() + assert(options.item).clear() end end return entity @@ -603,7 +603,8 @@ end --- @param n number --- @return string function ExpUtil.comma_value(n) -- credit http://richard.warburton.it - local left, num, right = string.match(n, "^([^%d]*%d)(%d*)(.-)$") + local left, num, right = string.match(n, "^([^%d]*%d)(%d*)(.-)$") + assert(left and num and right) return left .. (num:reverse():gsub("(%d%d%d)", "%1, "):reverse()) .. right end