diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2017-11-26 18:24:01 +0100 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2017-11-26 18:24:01 +0100 |
| commit | 05c8d229afc3d88f4c368a648e96b049ccd2fba3 (patch) | |
| tree | 250d2da4cb45f697d2a10494dda8f4c025ae9acd /Source/Core/Common/Config/Config.cpp | |
| parent | 653977cec758514027a0c73937b781f60c18ced9 (diff) | |
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.
Diffstat (limited to 'Source/Core/Common/Config/Config.cpp')
| -rw-r--r-- | Source/Core/Common/Config/Config.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp index a3504f80d2..342ef8ec6d 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -101,15 +101,14 @@ const std::string& GetSystemName(System system) return system_to_name.at(system); } -System GetSystemFromName(const std::string& name) +std::optional<System> GetSystemFromName(const std::string& name) { const auto system = std::find_if(system_to_name.begin(), system_to_name.end(), [&name](const auto& entry) { return entry.second == name; }); if (system != system_to_name.end()) return system->first; - _assert_msg_(COMMON, false, "Programming error! Couldn't convert '%s' to system!", name.c_str()); - return System::Main; + return {}; } const std::string& GetLayerName(LayerType layer) |
