Allow yaml-cpp exception to be caught in the loader and set as error
This allows for better debugging: the exception shows where in the file the error has occurred.
This commit is contained in:
@@ -83,20 +83,14 @@ bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
||||
|
||||
bool loadModelFromYaml(ModelData& model, const QByteArray& data)
|
||||
{
|
||||
try {
|
||||
YAML::Node node = loadYamlFromByteArray(data);
|
||||
node >> model;
|
||||
} catch (const std::runtime_error& e) {
|
||||
qDebug() << "YAML::ParserException: " << e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data)
|
||||
{
|
||||
try {
|
||||
YAML::Node node = loadYamlFromByteArray(data);
|
||||
node >> settings;
|
||||
if (settings.version < CPN_CURRENT_SETTINGS_VERSION) {
|
||||
@@ -107,10 +101,6 @@ bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data
|
||||
QMessageBox::critical(NULL, CPN_STR_APP_NAME, QCoreApplication::translate("EdgeTXInterface", "Companion does not support settings version %1!").arg(settings.version));
|
||||
return false;
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
qDebug() << "YAML::ParserException: " << e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -98,18 +98,18 @@ void operator>>(const YAML::Node& node, T (&value)[N])
|
||||
if (!node) return;
|
||||
if (node.IsMap()) {
|
||||
for (const auto& elmt : node) {
|
||||
int idx = -1;
|
||||
try {
|
||||
int idx = std::stoi(elmt.first.Scalar());
|
||||
if (idx < 0 || idx >= (int)N) return;
|
||||
|
||||
if (elmt.second.IsMap() && (elmt.second.size() == 1) &&
|
||||
elmt.second["val"]) {
|
||||
elmt.second["val"] >> value[idx];
|
||||
} else {
|
||||
elmt.second >> value[idx];
|
||||
}
|
||||
idx = std::stoi(elmt.first.Scalar());
|
||||
} catch (...) {
|
||||
return;
|
||||
}
|
||||
if (idx < 0 || idx >= (int)N) continue;
|
||||
|
||||
if (elmt.second.IsMap() && (elmt.second.size() == 1) &&
|
||||
elmt.second["val"]) {
|
||||
elmt.second["val"] >> value[idx];
|
||||
} else {
|
||||
elmt.second >> value[idx];
|
||||
}
|
||||
}
|
||||
} else if (node.IsSequence()) {
|
||||
|
||||
Reference in New Issue
Block a user