mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Provide custom YAML decoding error messages.
This should be a big help when trying to track down what went wrong.
This commit is contained in:
@@ -104,8 +104,12 @@ namespace YAML {
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::GameSettings& rhs) {
|
||||
if (!node.IsMap() || !node["folder"] || !node["type"])
|
||||
return false;
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'game settings' object must be a map");
|
||||
if (!node["folder"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'folder' key missing from 'game settings' object");
|
||||
if (!node["type"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'type' key missing from 'game settings' object");
|
||||
|
||||
if (node["type"].as<std::string>() == loot::GameSettings(loot::GameSettings::tes4).FolderName())
|
||||
rhs = loot::GameSettings(loot::GameSettings::tes4, node["folder"].as<std::string>());
|
||||
@@ -116,7 +120,7 @@ namespace YAML {
|
||||
else if (node["type"].as<std::string>() == loot::GameSettings(loot::GameSettings::fonv).FolderName())
|
||||
rhs = loot::GameSettings(loot::GameSettings::fonv, node["folder"].as<std::string>());
|
||||
else
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: invalid value for 'type' key in 'game settings' object");
|
||||
|
||||
if (node["name"])
|
||||
rhs.SetName(node["name"].as<std::string>());
|
||||
|
||||
@@ -43,12 +43,12 @@ namespace YAML {
|
||||
|
||||
static bool decode(const Node& node, std::set<T, Compare>& rhs) {
|
||||
if (!node.IsSequence())
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: set must be a sequence of elements");
|
||||
|
||||
rhs.clear();
|
||||
for (const auto &element : node) {
|
||||
if (!rhs.insert(element.template as<T>()).second)
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: set elements must be unique");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -77,12 +77,12 @@ namespace YAML {
|
||||
|
||||
static bool decode(const Node& node, std::unordered_set<T, Hash>& rhs) {
|
||||
if (!node.IsSequence())
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: unordered set must be a sequence of elements");
|
||||
|
||||
rhs.clear();
|
||||
for (const auto &element : node) {
|
||||
if (!rhs.insert(element.template as<T>()).second)
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: unordered set elements must be unique");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ namespace YAML {
|
||||
|
||||
static bool decode(const Node& node, loot::File& rhs) {
|
||||
if (!node.IsMap() && !node.IsScalar())
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'file' object must be a map or scalar");
|
||||
|
||||
if (node.IsMap()) {
|
||||
if (!node["name"])
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'name' key missing from 'file' map object");
|
||||
|
||||
std::string name = node["name"].as<std::string>();
|
||||
std::string condition, display;
|
||||
|
||||
@@ -62,14 +62,14 @@ namespace YAML {
|
||||
|
||||
static bool decode(const Node& node, loot::Location& rhs) {
|
||||
if (!node.IsMap() && !node.IsScalar())
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'location' object must be a map or scalar");
|
||||
|
||||
std::string url;
|
||||
std::string name;
|
||||
|
||||
if (node.IsMap()) {
|
||||
if (!node["link"])
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'link' key missing from 'location' map object");
|
||||
|
||||
url = node["link"].as<std::string>();
|
||||
if (node["name"])
|
||||
|
||||
@@ -86,8 +86,12 @@ namespace YAML {
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::Message& rhs) {
|
||||
if (!node.IsMap() || !node["type"] || !node["content"])
|
||||
return false;
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'message' object must be a map");
|
||||
if (!node["type"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'type' key missing from 'message' object");
|
||||
if (!node["content"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'content' key missing from 'message' object");
|
||||
|
||||
std::string type;
|
||||
type = node["type"].as<std::string>();
|
||||
@@ -113,7 +117,7 @@ namespace YAML {
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: multilingual messages must contain an English content string");
|
||||
}
|
||||
|
||||
// Make any substitutions at this point.
|
||||
|
||||
@@ -59,8 +59,12 @@ namespace YAML {
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::MessageContent& rhs) {
|
||||
if (!node.IsMap() || !node["str"] || !node["lang"])
|
||||
return false;
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'message content' object must be a map");
|
||||
if (!node["str"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'str' key missing from 'message content' object");
|
||||
if (!node["lang"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'lang' key missing from 'message content' object");
|
||||
|
||||
std::string str = node["str"].as<std::string>();
|
||||
unsigned int lang = loot::Language(node["lang"].as<std::string>()).Code();
|
||||
|
||||
@@ -75,8 +75,12 @@ namespace YAML {
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::PluginDirtyInfo& rhs) {
|
||||
if (!node.IsMap() || !node["crc"] || !node["util"])
|
||||
return false;
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'dirty info' object must be a map");
|
||||
if (!node["crc"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'crc' key missing from 'dirty info' object");
|
||||
if (!node["util"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'util' key missing from 'dirty info' object");
|
||||
|
||||
uint32_t crc = node["crc"].as<uint32_t>();
|
||||
int itm = 0, ref = 0, nav = 0;
|
||||
|
||||
@@ -153,8 +153,10 @@ namespace YAML {
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::PluginMetadata& rhs) {
|
||||
if (!node.IsMap() || !node["name"])
|
||||
return false;
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'plugin metadata' object must be a map");
|
||||
if (!node["name"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'name' key missing from 'plugin metadata' object");
|
||||
|
||||
rhs = loot::PluginMetadata(node["name"].as<std::string>());
|
||||
|
||||
@@ -178,7 +180,7 @@ namespace YAML {
|
||||
rhs.Tags(node["tag"].as< std::set<loot::Tag> >());
|
||||
if (node["dirty"]) {
|
||||
if (rhs.IsRegexPlugin())
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'dirty' key must not be present in a regex 'plugin metadata' object");
|
||||
else
|
||||
rhs.DirtyInfo(node["dirty"].as< std::set<loot::PluginDirtyInfo> >());
|
||||
}
|
||||
|
||||
@@ -63,12 +63,12 @@ namespace YAML {
|
||||
|
||||
static bool decode(const Node& node, loot::Tag& rhs) {
|
||||
if (!node.IsMap() && !node.IsScalar())
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'tag' object must be a map or scalar");
|
||||
|
||||
std::string condition, tag;
|
||||
if (node.IsMap()) {
|
||||
if (!node["name"])
|
||||
return false;
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'name' key missing from 'tag' map object");
|
||||
|
||||
tag = node["name"].as<std::string>();
|
||||
if (node["condition"])
|
||||
|
||||
Reference in New Issue
Block a user