From 3075ec583d6eca9beb689a1682d3bb44c095e694 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sun, 7 Jul 2024 16:08:42 +0800 Subject: [PATCH] fix: in config manager throw exception when facing duplicated setting name instead of slient skip --- src/ConfigManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ConfigManager.cpp b/src/ConfigManager.cpp index f0e0c5d..3c16549 100644 --- a/src/ConfigManager.cpp +++ b/src/ConfigManager.cpp @@ -2,6 +2,7 @@ #include "EncodingHelper.hpp" #include "IOHelper.hpp" +#include namespace YYCC::ConfigManager { @@ -17,7 +18,11 @@ namespace YYCC::ConfigManager { m_CfgFilePath = cfg_file_path; // assign 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"); + } } }