refactor(config): Throw missing section error
Makes error messages less confusing if for some reason a key in an non-existent section is requested.
This commit is contained in:
parent
b11fa81f19
commit
5dc6e7a7aa
@ -84,7 +84,10 @@ class config {
|
|||||||
template <typename T = string>
|
template <typename T = string>
|
||||||
T get(const string& section, const string& key) const {
|
T get(const string& section, const string& key) const {
|
||||||
auto it = m_sections.find(section);
|
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 + "\"");
|
throw key_error("Missing parameter \"" + section + "." + key + "\"");
|
||||||
}
|
}
|
||||||
return dereference<T>(section, key, it->second.at(key), convert<T>(string{it->second.at(key)}));
|
return dereference<T>(section, key, it->second.at(key), convert<T>(string{it->second.at(key)}));
|
||||||
|
Loading…
Reference in New Issue
Block a user