-
-
Notifications
You must be signed in to change notification settings - Fork 77
Fix server crash when mods.json is empty #455
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
base: minor
Are you sure you want to change the base?
Conversation
src/TResourceManager.cpp
Outdated
|
|
||
| if (std::filesystem::exists(Path + "/mods.json")) { | ||
| auto modsJsonPath = Path + "/mods.json"; | ||
| if (std::filesystem::exists(modsJsonPath) && std::filesystem::file_size(modsJsonPath) > 0) { |
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.
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"
src/TResourceManager.cpp
Outdated
| 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) { |
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.
Could there be some kind of attempt to regenerate the file here? This way the protect command just gets completely disregarded with no info.
|
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
b9cce23 to
96c7491
Compare
| inStream >> modsDB; | ||
| inStream.close(); | ||
| } else { | ||
| beammp_warn("Mods database file is empty, regenerating it"); |
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 might be overlooking something here, but is the regeneration code missing?
Check file size before attempting to parse mods.json.
Empty files are now gracefully ignored instead of causing a parse error.