From 5dc6e7a7aa7f19b6dd0d2b2c80ec2a9ddadbcc5f Mon Sep 17 00:00:00 2001 From: patrick96 Date: Tue, 6 Oct 2020 18:22:10 +0200 Subject: [PATCH] refactor(config): Throw missing section error Makes error messages less confusing if for some reason a key in an non-existent section is requested. --- include/components/config.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/components/config.hpp b/include/components/config.hpp index 9c15f13e..30375a49 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -84,7 +84,10 @@ class config { template T get(const string& section, const string& key) const { auto it = m_sections.find(section); - if (it == m_sections.end() || it->second.find(key) == it->second.end()) { + if (it == m_sections.end()) { + throw key_error("Missing section \"" + section + "\""); + } + if (it->second.find(key) == it->second.end()) { throw key_error("Missing parameter \"" + section + "." + key + "\""); } return dereference(section, key, it->second.at(key), convert(string{it->second.at(key)}));