Skip to content

Conversation

@Kipstz
Copy link
Contributor

@Kipstz Kipstz commented Dec 24, 2025

Check file size before attempting to parse mods.json.
Empty files are now gracefully ignored instead of causing a parse error.


if (std::filesystem::exists(Path + "/mods.json")) {
auto modsJsonPath = Path + "/mods.json";
if (std::filesystem::exists(modsJsonPath) && std::filesystem::file_size(modsJsonPath) > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a beammp_warn log be made when the file is empty? That way there's at least a trace of something not going as intended. Something along the lines of "Mods json database is empty, ignoring it"

auto modsDBPath = Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "/Client/mods.json";

if (std::filesystem::exists(modsDBPath)) {
if (std::filesystem::exists(modsDBPath) && std::filesystem::file_size(modsDBPath) > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be some kind of attempt to regenerate the file here? This way the protect command just gets completely disregarded with no info.

@WiserTixx
Copy link
Collaborator

Yes, this would technically solve the issue linked. However I'd like to figure out why that happened in the first place before closing it.

Check file size before attempting to parse mods.json.
Empty files are now gracefully ignored instead of causing a parse error.

Closes BeamMP#442
@Kipstz Kipstz force-pushed the fix-empty-mods-json branch from b9cce23 to 96c7491 Compare December 27, 2025 22:06
inStream >> modsDB;
inStream.close();
} else {
beammp_warn("Mods database file is empty, regenerating it");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be overlooking something here, but is the regeneration code missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants