From f3f0e8966d68de5eb93b5d1cc3f5c09bd5ac807a Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 1 Oct 2024 21:27:30 +0100 Subject: [PATCH] run_command: prepend the name of the command in case of error. --- CHANGELOG.md | 1 + worldeditadditions_core/core/run_command.lua | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ee766..d8dd4d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Note to self: See the bottom of this file for the release template text. - Added `//uasparse` command to show the vectors produced by a given UAS expression. - Implementation by @VorTechnix ### Bugfixes and changes +- When commands produce an error, the name of the command that produced the error is now also printed. Useful when using e.g. [`//multi`](https://worldeditadditions.mooncarrot.space/Reference/#multi) etc. - Don't warn on failed registration of `//flora` → [`//bonemeal`](https://worldeditadditions.mooncarrot.space/Reference/#bonemeal) if the `bonemeal` mod isn't installed (e.g. in MineClone2) - thanks @VorTechnix in #106 - Improve documentation of [`//noise2d`](https://worldeditadditions.mooncarrot.space/Reference/#noise2d). If it still doesn't make sense, please let me know. It's a complicated command that needs reworking a bit to be easier to use. - Alias `//napply` to [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply) diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index 01df9af..8dfbce6 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -19,11 +19,16 @@ local human_size = wea_c.format.human_size local function run_command_stage2(player_name, func, parse_result, tbl_event) wea_c:emit("pre-execute", tbl_event) local success, result_message = func(player_name, wea_c.table.unpack(parse_result)) + print("DEBUG:run_command_stage2 SUCCESS", success, "RESULT_MESSAGE", result_message) + if not success then + + result_message = "[//"..tostring(tbl_event.cmdname).."] "..result_message + end + if result_message then -- TODO: If we were unsuccessful, then colour the message red worldedit.player_notify(player_name, result_message) end - tbl_event.success = success tbl_event.result = result_message wea_c:emit("post-execute", tbl_event) @@ -110,7 +115,7 @@ local function run_command(cmdname, options, player_name, paramtext) local parse_result = { options.parse(paramtext) } local success = table.remove(parse_result, 1) if not success then - worldedit.player_notify(player_name, tostring(parse_result[1]) or "Invalid usage (no further error message was provided by the command. This is probably a bug.)") + worldedit.player_notify(player_name, ("[//"..tostring(cmdname).."] "..tostring(parse_result[1])) or "Invalid usage (no further error message was provided by the command. This is probably a bug.)") return false end