fix: in config manager throw exception when facing duplicated setting name instead of slient skip

This commit is contained in:
yyc12345 2024-07-07 16:08:42 +08:00
parent 2e28dd4c48
commit 3075ec583d

View File

@ -2,6 +2,7 @@
#include "EncodingHelper.hpp" #include "EncodingHelper.hpp"
#include "IOHelper.hpp" #include "IOHelper.hpp"
#include <stdexcept>
namespace YYCC::ConfigManager { namespace YYCC::ConfigManager {
@ -17,7 +18,11 @@ namespace YYCC::ConfigManager {
m_CfgFilePath = cfg_file_path; m_CfgFilePath = cfg_file_path;
// assign settings // assign settings
for (auto* setting : settings) { for (auto* setting : settings) {
m_Settings.try_emplace(setting->GetName(), setting); auto result = m_Settings.try_emplace(setting->GetName(), setting);
if (!result.second) {
// if not inserted because duplicated, raise exception
throw std::invalid_argument("Duplicated setting name");
}
} }
} }