-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Prevent loading of mods with invalid names #16904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
compmstr
wants to merge
9
commits into
luanti-org:master
Choose a base branch
from
compmstr:mod-name-filter-tweak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1efcfa
Stop loading mod if mod name is invalid
compmstr d8f08f3
Fix indents (should be tabs)
compmstr 9ab1852
Update docs for module `name` field
compmstr 817cd45
Add module load error handling
compmstr 8c60ce8
whitespace fixes
compmstr 41badce
Move mod error handling into new ModErrors class
compmstr 2e240e2
Move imports to the file where they are used
compmstr 61f1f06
Update copyright for new files
compmstr 2af97e1
Switch to unordered_(set|map) for errors
compmstr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Luanti | ||
| // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| // Copyright (C) 2026 Luanti developers | ||
|
|
||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
| #include <sstream> | ||
| #include "mod_errors.h" | ||
| #include "common/c_internal.h" | ||
| #include "log.h" | ||
| #include "exceptions.h" | ||
|
|
||
| struct SingleModErrors { | ||
| std::unordered_set<std::string> messages; | ||
| bool was_handled; | ||
| }; | ||
|
|
||
| static std::unordered_map<std::string, SingleModErrors> mod_errors; | ||
|
|
||
| void ModErrors::logErrors() { | ||
| auto error_handling_mode = get_mod_error_handling_mode(); | ||
| if (error_handling_mode == ModErrorHandlingMode::IgnoreModError) { | ||
| return; | ||
| } | ||
|
|
||
| for (auto &pair : mod_errors) { | ||
| const auto path = pair.first; | ||
| SingleModErrors& err = pair.second; | ||
|
|
||
| if (!err.was_handled && !err.messages.empty()) { | ||
| err.was_handled = true; | ||
| std::ostringstream os; | ||
| os << "Mod at " << path << ":" << std::endl; | ||
| for (const auto& msg : err.messages) { | ||
| os << "\t" << msg << std::endl; | ||
| } | ||
| if (error_handling_mode == ModErrorHandlingMode::ThrowModError) | ||
| throw ModError(os.str()); | ||
| else | ||
| warningstream << os.str(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| void ModErrors::setModError(const std::string &path, std::string error_message) { | ||
| SingleModErrors &cur = mod_errors[path]; | ||
| auto result = cur.messages.emplace(error_message); | ||
| if (result.second) { | ||
| // New message was added, reset the was_handled flag | ||
| cur.was_handled = false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Luanti | ||
| // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| // Copyright (C) 2026 Luanti developers | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| class ModErrors { | ||
| public: | ||
| static void logErrors(); | ||
| static void setModError(const std::string &path, std::string error_message); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When starting Luanti in the "Start game" tab, the following warnings are logged. When I click "Configure mods", the same bunch of warnings are logged - again.
lua_api.mdA-z_-ora-z_-might be the best retro-fit.Prevent loading of modsis done bymod.checkAndLog();inServerModManager::loadMods, where the server will not load the mods that do not obey the naming conventions.EDIT: Whereas the naming is enforced upon server start-up, there is also lack of documentation on mod names in
lua_api.md.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll notice that nothing else prints to the log in this function. This is by design - it would be too spammy in the main menu. You should just return false here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, should I just drop the logging altogether, or try to find somewhere to log once for mod debugging purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I could add a message to
deprecation_msgs, so that it gets logged out when other mod issues are.I could also set up a new
error_msgsthat contains this message, as well as things like "Mod ... missing init.lua" (the other case where we skip loading a log). I could log it from withincheckAndLogthe same way deprecation messages are.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at how the missing init.lua is validated because it's the same style of issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got bit by the silent failure of the mod from a missing
init.luawhen I first tried to test this PR. Ideally we could log at least once whenever there's an error loading the mod.I'll take another pass at this, see if I can get these to log out inside
checkAndLog, since that's less spammy.