From 05c8d229afc3d88f4c368a648e96b049ccd2fba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 26 Nov 2017 18:24:01 +0100 Subject: 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. --- Source/Core/UICommon/CommandLineParse.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Source/Core/UICommon/CommandLineParse.cpp') diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index 1ca4bb90e8..683738479f 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -40,8 +41,12 @@ public: std::getline(buffer, section, '.'); std::getline(buffer, key, '='); std::getline(buffer, value, '='); - Config::System system = Config::GetSystemFromName(system_str); - m_values.emplace_back(std::make_tuple(Config::ConfigLocation{system, section, key}, value)); + const std::optional system = Config::GetSystemFromName(system_str); + if (system) + { + m_values.emplace_back( + std::make_tuple(Config::ConfigLocation{*system, section, key}, value)); + } } } -- cgit v1.2.3