Prevent loading of mods with invalid names#16904
Prevent loading of mods with invalid names#16904compmstr wants to merge 9 commits intoluanti-org:masterfrom
Conversation
Logs message to warningstream
|
Alternative PR: #16719 |
| if (info.exists("name")) { | ||
| spec.name = info.get("name"); | ||
| spec.is_name_explicit = true; | ||
| if (!string_allowed(spec.name, MODNAME_ALLOWED_CHARS)) { |
There was a problem hiding this comment.
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.
Error loading mod "xxx/games/VoxeLibre/mods/PLAYER": Mod does not follow naming conventions: Only characters [a-z0-9_] are allowed.
Error loading mod "xxx/mods/worldedit-modpack/bonkers": Mod does not follow naming conventions: Only characters [a-z0-9_] are allowed.
Error loading mod "xxx/mods/worldedit-modpack": Mod does not follow naming conventions: Only characters [a-z0-9_] are allowed.
Error loading mod "xxx/mods/skyblock": Mod does not fo llow naming conventions: Only characters [a-z0-9_] are allowed.
Error loading mod "xxx/mods/nested_modpack/modpack_a1": Mod does not follow naming conventions: Only characters [a-z0-9_] are allowed.
Error loading mod "xxx/mods/nested_modpack/modpack_b2": Mod does not follow naming conventions: Only characters [a-z0-9_] are allowed.
Error loading mod "xxx/mods/nested_modpack": Mod does not follow naming conventions: Only characters [a-z0-9_] are allowed.
- The warnings should only logged once per mod(pack) to avoid spam.
- From what I could(n't find), modpacks seem to have no naming rules defined in
lua_api.md- This needs documenting.
A-z_-ora-z_-might be the best retro-fit.
- Perhaps misleading PR title.
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.
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.
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.
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_msgs that 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 within checkAndLog the same way deprecation messages are.
There was a problem hiding this comment.
Look at how the missing init.lua is validated because it's the same style of issue
There was a problem hiding this comment.
I got bit by the silent failure of the mod from a missing init.lua when 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.
Update allowed mod name characters to include A-Z (upper-case)
ModSpec::mod_load_error_msgs holds the set of errors (per file) When `checkAndLog` is called, we also log mod load errors Logging, ignoring, and erroring are all configured by a new setting (defaulted to log)
|
Would this be cleaner if I set up something like a |
Since the errors are explicily for mods that did not get loaded, it made more sense to have this be separate from ModSpec.
|
I moved this mod error handling code into a new |
Move back to original valid name characters
Fix error message to reflect actual allowed characters.

Logs message to warningstream
Add compact, short information about your PR for easier understanding:
parseModContentsto check for invalid name when loading. Logs and skips mods containing invalid characters.name#16478I realize there's already an open PR for this, but it has been inactive for a couple of weeks at this point.
To do
This PR is Ready for Review.
How to test
As documented in the issue, set up a mod with invalid characters in the
namefield.ex:
Prior to this fix, the mod would load, and show up oddly in the mod list.
Afterwards, there is a WARN log, and the mod does not get loaded/shown.