From 98fbbafef78057c818fb02b15c27e38ad2f5b5bc Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 28 Apr 2026 15:56:07 +0100 Subject: config/errors: Report and categorize errors properly for actions (#14192) Makes all errors categorized, some not displayed, some displayed. All errors can be obtained after hl.dispatch() --- .../lua/bindings/LuaBindingsRegistration.cpp | 39 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/config/lua/bindings/LuaBindingsRegistration.cpp') diff --git a/src/config/lua/bindings/LuaBindingsRegistration.cpp b/src/config/lua/bindings/LuaBindingsRegistration.cpp index ba6804a9..0cb59364 100644 --- a/src/config/lua/bindings/LuaBindingsRegistration.cpp +++ b/src/config/lua/bindings/LuaBindingsRegistration.cpp @@ -26,6 +26,31 @@ static int hlPrint(lua_State* L) { return 0; } +static SDispatchResult dispatchResultFromLua(lua_State* L, int idx) { + SDispatchResult result; + + if (!lua_istable(L, idx)) + return result; + + lua_getfield(L, idx, "pass_event"); + result.passEvent = lua_toboolean(L, -1); + lua_pop(L, 1); + + lua_getfield(L, idx, "ok"); + if (lua_isboolean(L, -1)) + result.success = lua_toboolean(L, -1); + lua_pop(L, 1); + + if (!result.success) { + lua_getfield(L, idx, "error"); + if (lua_isstring(L, -1)) + result.error = lua_tostring(L, -1); + lua_pop(L, 1); + } + + return result; +} + void Internal::registerBindingsImpl(lua_State* L, CConfigManager* mgr) { Objects::CLuaTimer{}.setup(L); Objects::CLuaEventSubscription{}.setup(L); @@ -40,15 +65,21 @@ void Internal::registerBindingsImpl(lua_State* L, CConfigManager* mgr) { int status = LUA_OK; if (auto* mgr = CConfigManager::fromLuaState(L); mgr) - status = mgr->guardedPCall(0, 0, 0, CConfigManager::LUA_TIMEOUT_KEYBIND_CALLBACK_MS, "keybind callback"); + status = mgr->guardedPCall(0, 1, 0, CConfigManager::LUA_TIMEOUT_KEYBIND_CALLBACK_MS, "keybind callback"); else - status = lua_pcall(L, 0, 0, 0); + status = lua_pcall(L, 0, 1, 0); if (status != LUA_OK) { - Config::Lua::mgr()->addError(std::format("error in keybind lambda: {}", lua_tostring(L, -1))); + Config::Lua::Bindings::Internal::reportError(L, + Config::Actions::SActionError{std::format("error in keybind lambda: {}", lua_tostring(L, -1)), + Config::Actions::eActionErrorLevel::ERROR, Config::Actions::eActionErrorCode::LUA_ERROR}); lua_pop(L, 1); + return {.success = false, .error = "lua keybind error"}; } - return {}; + + auto result = dispatchResultFromLua(L, -1); + lua_pop(L, 1); + return result; }; lua_newtable(L); -- cgit v1.2.3