force ModImpl::m_saved to an object when loading saved.json

This commit is contained in:
matcool 2023-02-08 15:29:48 -03:00
parent eb7576e6ea
commit 28b26220c8
No known key found for this signature in database
GPG key ID: BF58756086D7AB1C

View file

@ -124,8 +124,6 @@ Result<> Mod::Impl::loadData() {
if (ghc::filesystem::exists(settingPath)) { if (ghc::filesystem::exists(settingPath)) {
GEODE_UNWRAP_INTO(auto settingData, utils::file::readString(settingPath)); GEODE_UNWRAP_INTO(auto settingData, utils::file::readString(settingPath));
try { try {
std::string err;
// parse settings.json // parse settings.json
auto json = json::parse(settingData); auto json = json::parse(settingData);
@ -169,13 +167,15 @@ Result<> Mod::Impl::loadData() {
if (ghc::filesystem::exists(savedPath)) { if (ghc::filesystem::exists(savedPath)) {
GEODE_UNWRAP_INTO(auto data, utils::file::readString(savedPath)); GEODE_UNWRAP_INTO(auto data, utils::file::readString(savedPath));
std::string err;
try { try {
m_saved = json::parse(data); m_saved = json::parse(data);
} catch (std::exception& err) { } catch (std::exception& err) {
return Err(std::string("Unable to parse saved values: ") + err.what()); return Err(std::string("Unable to parse saved values: ") + err.what());
} }
if (!m_saved.is_object()) {
log::warn("saved.json was somehow not an object, forcing it to one");
m_saved = json::Object();
}
} }
return Ok(); return Ok();