Config: Handle unknown system strings better
Currently, a simple typo in the system name will trigger an assert message that complains about a "programming error". This is not user friendly and misleading. So this changes GetSystemFromName to return an std::optional, which allows for callers to check whether the system exists and handle failures better.
This commit is contained in:
1 parent
653977cec7
commit
05c8d229af
4 files changed
+14
-8
No files matched your search
@@ -157,8 +157,9 @@ static ConfigLocation MapINIToRealLocation(const std::string& section, const std
|
||||
std::getline(buffer, config_section, '.');
|
||||
fail |= buffer.fail();
|
||||
|
||||
if (!fail)
|
||||
return {Config::GetSystemFromName(system_str), config_section, key};
|
||||
const std::optional<Config::System> system = Config::GetSystemFromName(system_str);
|
||||
if (!fail && system)
|
||||
return {*system, config_section, key};
|
||||
|
||||
WARN_LOG(CORE, "Unknown game INI option in section %s: %s", section.c_str(), key.c_str());
|
||||
return {Config::System::Main, "", ""};
|
||||
|
||||
Reference in new issue
Block a user