1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

Improve error handling of config nodes

These conditions are most likely only gonna be met during development
This commit is contained in:
Megamouse 2020-07-28 23:11:27 +02:00
parent ef3e8d26ce
commit 1c6003acd5
2 changed files with 28 additions and 3 deletions

View File

@ -3,6 +3,8 @@
#include "config_adapter.h"
#include "Emu/system_config.h"
LOG_CHANNEL(cfg_log, "CFG");
// Helper methods to interact with YAML and the config settings.
namespace cfg_adapter
{
@ -29,7 +31,18 @@ namespace cfg_adapter
YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end)
{
return begin == end ? node : get_node(node[*begin], begin + 1, end); // TODO
if (begin == end)
{
return node;
}
if (!node || !node.IsMap())
{
cfg_log.fatal("Node error. A cfg_location does not match its cfg::node");
return YAML::Node();
}
return get_node(node[*begin], begin + 1, end); // TODO
}
YAML::Node get_node(const YAML::Node& node, cfg_location loc)

View File

@ -500,12 +500,24 @@ QStringList emu_settings::GetSettingOptions(emu_settings_type type) const
std::string emu_settings::GetSettingDefault(emu_settings_type type) const
{
return cfg_adapter::get_node(m_defaultSettings, settings_location[type]).Scalar();
if (auto node = cfg_adapter::get_node(m_defaultSettings, settings_location[type]); node && node.IsScalar())
{
return node.Scalar();
}
cfg_log.fatal("GetSettingDefault(type=%d) could not retrieve the requested node", static_cast<int>(type));
return "";
}
std::string emu_settings::GetSetting(emu_settings_type type) const
{
return cfg_adapter::get_node(m_currentSettings, settings_location[type]).Scalar();
if (auto node = cfg_adapter::get_node(m_currentSettings, settings_location[type]); node && node.IsScalar())
{
return node.Scalar();
}
cfg_log.fatal("GetSetting(type=%d) could not retrieve the requested node", static_cast<int>(type));
return "";
}
void emu_settings::SetSetting(emu_settings_type type, const std::string& val)