mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-25 04:02:42 +01:00
patch manager: move try catch block to yaml.cpp
This commit is contained in:
parent
591624b96c
commit
1c7a318413
@ -363,9 +363,8 @@ bool patch_engine::add_patch_data(YAML::Node node, patch_info& info, u32 modifie
|
||||
p_data.offset = addr_node.as<u32>(0) + modifier;
|
||||
p_data.original_value = value_node.IsScalar() ? value_node.Scalar() : "";
|
||||
|
||||
// Use try/catch instead of YAML::Node::as<T>(fallback) in order to get an error message
|
||||
try
|
||||
{
|
||||
std::string error_message;
|
||||
|
||||
switch (p_data.type)
|
||||
{
|
||||
case patch_type::bef32:
|
||||
@ -373,20 +372,20 @@ bool patch_engine::add_patch_data(YAML::Node node, patch_info& info, u32 modifie
|
||||
case patch_type::bef64:
|
||||
case patch_type::lef64:
|
||||
{
|
||||
p_data.value.double_value = value_node.as<f64>();
|
||||
p_data.value.double_value = get_yaml_node_value<f64>(value_node, error_message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
p_data.value.long_value = value_node.as<u64>();
|
||||
p_data.value.long_value = get_yaml_node_value<u64>(value_node, error_message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
||||
if (!error_message.empty())
|
||||
{
|
||||
const std::string error_message = fmt::format("Skipping patch data entry: [ %s, 0x%.8x, %s ] (key: %s) %s",
|
||||
p_data.type, p_data.offset, p_data.original_value.empty() ? "?" : p_data.original_value, info.hash, e.what());
|
||||
error_message = fmt::format("Skipping patch data entry: [ %s, 0x%.8x, %s ] (key: %s) %s",
|
||||
p_data.type, p_data.offset, p_data.original_value.empty() ? "?" : p_data.original_value, info.hash, error_message);
|
||||
append_log_message(log_messages, error_message);
|
||||
patch_log.error("%s", error_message);
|
||||
return false;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "util/yaml.hpp"
|
||||
#include "Utilities/types.h"
|
||||
|
||||
std::pair<YAML::Node, std::string> yaml_load(const std::string& from)
|
||||
{
|
||||
@ -15,3 +16,21 @@ std::pair<YAML::Node, std::string> yaml_load(const std::string& from)
|
||||
|
||||
return{result, ""};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T get_yaml_node_value(YAML::Node node, std::string& error_message)
|
||||
{
|
||||
try
|
||||
{
|
||||
return node.as<T>();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
error_message = e.what();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
template u64 get_yaml_node_value<u64>(YAML::Node, std::string&);
|
||||
template f64 get_yaml_node_value<f64>(YAML::Node, std::string&);
|
||||
|
@ -18,3 +18,7 @@
|
||||
|
||||
// Load from string and consume exception
|
||||
std::pair<YAML::Node, std::string> yaml_load(const std::string& from);
|
||||
|
||||
// Use try/catch in YAML::Node::as<T>() instead of YAML::Node::as<T>(fallback) in order to get an error message
|
||||
template <typename T>
|
||||
T get_yaml_node_value(YAML::Node node, std::string& error_message);
|
||||
|
Loading…
Reference in New Issue
Block a user