From fd0401e781d2cf6e0ab44772afbfeaee635648b0 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Sat, 26 Sep 2026 23:22:18 +0000 Subject: [PATCH] Format names of players who never joined the instance Reports carry names from the controller, so the reported player, the reporter or the caller may never have joined this server. The exp_util formatter asserts the player exists, so those names now fall back to plain white text. The test stub of the formatter now requires a LuaPlayer like the real one, which made the existing receiver tests fail before the fix. Co-Authored-By: Claude Opus 5.5 --- exp_reports/module/control.lua | 14 +++++++++++++- exp_reports/test/module/env.lua | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/exp_reports/module/control.lua b/exp_reports/module/control.lua index 17b7d102..0734f960 100644 --- a/exp_reports/module/control.lua +++ b/exp_reports/module/control.lua @@ -9,7 +9,8 @@ player who asked once it arrives, if they are still online. local clusterio_api = require("modules/clusterio/api") local ExpUtil = require("modules/exp_util") -local format_player_name = ExpUtil.format_player_name_locale +local format_player_name_locale = ExpUtil.format_player_name_locale +local format_rich_text_color_locale = ExpUtil.format_rich_text_color_locale --- @class ExpReports local ExpReports = { @@ -88,6 +89,17 @@ local function get_online_player(name) return nil end +--- Names come from the controller, so the player may never have joined this server +--- @param name string +--- @return LocalisedString +local function format_player_name(name) + local player = game.get_player(name) + if player then + return format_player_name_locale(player) + end + return format_rich_text_color_locale(name, ExpUtil.color.white) +end + --- The controller accepted a report --- @param payload { report: ExpReports.Report, reports: ExpReports.Report[] } function ExpReports.receive_created(payload) diff --git a/exp_reports/test/module/env.lua b/exp_reports/test/module/env.lua index fc3b6c62..62c4ca69 100644 --- a/exp_reports/test/module/env.lua +++ b/exp_reports/test/module/env.lua @@ -23,8 +23,12 @@ return Framework.suite(function(env) --- @cast env ExpReports.TestEnv env.extend_requires{ ["modules/exp_util"] = { - format_player_name_locale = function(name) return name end, - color = { orange_red = "orange_red" }, + format_player_name_locale = function(player) + assert(type(player) == "table", "format_player_name_locale takes a LuaPlayer") + return player.name + end, + format_rich_text_color_locale = function(message) return message end, + color = { orange_red = "orange_red", white = "white" }, }, } env.Reports = assert(loadfile(plugin_root .. "/module/control.lua"))() --- @type ExpReports