From 4125ce877d9f494a2a88356fc399194ac6aa0e85 Mon Sep 17 00:00:00 2001 From: JosiahWI <41302989+JosiahWI@users.noreply.github.com> Date: Wed, 19 Mar 2025 12:43:19 -0500 Subject: [PATCH] Do not discover mod directories that fail parsing (#15917) The root issue of the unit test failure is that all directories that are found in the mod search are counted as mods, even if they are detected to be invalid as such by the parser. For example, the presence of an init.lua file is required, and the parser will return false if one is not found. This return value was completely ignored. Simply counting the mod conditionally on the parsing success makes the modserver tests pass on MSVC. --- src/content/mods.cpp | 5 +++-- src/content/mods.h | 2 +- src/script/lua_api/l_mainmenu.cpp | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/content/mods.cpp b/src/content/mods.cpp index 5a9281f7d1..333f1d24da 100644 --- a/src/content/mods.cpp +++ b/src/content/mods.cpp @@ -175,8 +175,9 @@ std::map getModsInPath( mod_virtual_path.append(virtual_path).append("/").append(modname); ModSpec spec(modname, mod_path, part_of_modpack, mod_virtual_path); - parseModContents(spec); - result[modname] = std::move(spec); + if (parseModContents(spec)) { + result[modname] = std::move(spec); + } } return result; } diff --git a/src/content/mods.h b/src/content/mods.h index a7e1e50415..fc98d92987 100644 --- a/src/content/mods.h +++ b/src/content/mods.h @@ -78,7 +78,7 @@ struct ModSpec * * @returns false if not a mod */ -bool parseModContents(ModSpec &mod); +[[nodiscard]] bool parseModContents(ModSpec &mod); /** * Gets a list of all mods and modpacks in path diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 43087c978d..0969bb5258 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -385,7 +385,8 @@ int ModApiMainMenu::l_get_content_info(lua_State *L) if (spec.type == "mod") { ModSpec spec; spec.path = path; - parseModContents(spec); + // TODO return nothing on failure (needs callers to handle it) + static_cast(parseModContents(spec)); // Dependencies lua_newtable(L);