Turn missing Horizons files from a warning to an error. Improve error message quality of OrVerifiers

This commit is contained in:
Alexander Bock
2025-02-04 03:00:25 +01:00
parent efb7599b3d
commit 7079845cf2
4 changed files with 43 additions and 34 deletions
@@ -43,17 +43,19 @@ namespace {
} // namespace
namespace {
constexpr openspace::properties::Property::PropertyInfo HorizonsTextFileInfo = {
"HorizonsTextFile",
"Horizons Text File",
constexpr openspace::properties::Property::PropertyInfo HorizonsFileInfo = {
"HorizonsFile",
"Horizons File",
"This value is the path to the file or files generated by Horizons with "
"either a Vector table or an Observer table with the correct settings.",
openspace::properties::Property::Visibility::AdvancedUser
};
struct [[codegen::Dictionary(HorizonsTranslation)]] Parameters {
// [[codegen::verbatim(HorizonsTextFileInfo.description)]]
std::variant<std::string, std::vector<std::string>> horizonsTextFile;
// [[codegen::verbatim(HorizonsFileInfo.description)]]
std::variant<
std::filesystem::path, std::vector<std::filesystem::path>
> horizonsFile [[codegen::key("HorizonsTextFile")]];
};
#include "horizonstranslation_codegen.cpp"
} // namespace
@@ -65,11 +67,11 @@ documentation::Documentation HorizonsTranslation::Documentation() {
}
HorizonsTranslation::HorizonsTranslation()
: _horizonsTextFiles(HorizonsTextFileInfo)
: _horizonsFiles(HorizonsFileInfo)
{
addProperty(_horizonsTextFiles);
addProperty(_horizonsFiles);
_horizonsTextFiles.onChange([this](){
_horizonsFiles.onChange([this](){
requireUpdate();
notifyObservers();
loadData();
@@ -81,30 +83,22 @@ HorizonsTranslation::HorizonsTranslation(const ghoul::Dictionary& dictionary)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
if (std::holds_alternative<std::string>(p.horizonsTextFile)) {
std::string file = std::get<std::string>(p.horizonsTextFile);
if (!std::filesystem::is_regular_file(absPath(file))) {
LWARNING(std::format("The Horizons text file '{}' could not be found", file));
return;
}
std::vector<std::string> files;
files.push_back(file);
_horizonsTextFiles = files;
if (std::holds_alternative<std::filesystem::path>(p.horizonsFile)) {
std::filesystem::path file = std::get<std::filesystem::path>(p.horizonsFile);
_horizonsFiles = { file.string() };
}
else if (std::holds_alternative<std::vector<std::string>>(p.horizonsTextFile)) {
const std::vector<std::string> files =
std::get<std::vector<std::string>>(p.horizonsTextFile);
else if (std::holds_alternative<std::vector<std::filesystem::path>>(p.horizonsFile)) {
const std::vector<std::filesystem::path> files =
std::get<std::vector<std::filesystem::path>>(p.horizonsFile);
for (const std::string& file : files) {
if (!std::filesystem::is_regular_file(absPath(file))) {
LWARNING(std::format(
"The Horizons text file '{}' could not be found", file
));
return;
}
}
_horizonsTextFiles = files;
std::vector<std::string> f;
std::transform(
files.cbegin(),
files.end(),
std::back_inserter(f),
[](const std::filesystem::path& p) { return p.string(); }
);
_horizonsFiles = f;
}
else {
throw ghoul::MissingCaseException();
@@ -141,7 +135,7 @@ glm::dvec3 HorizonsTranslation::position(const UpdateData& data) const {
}
void HorizonsTranslation::loadData() {
for (const std::string& filePath : _horizonsTextFiles.value()) {
for (const std::string& filePath : _horizonsFiles.value()) {
std::filesystem::path file = absPath(filePath);
if (!std::filesystem::is_regular_file(file)) {
LWARNING(std::format("The Horizons text file '{}' could not be found", file));
@@ -87,7 +87,7 @@ private:
bool loadCachedFile(const std::filesystem::path& file);
void saveCachedFile(const std::filesystem::path& file) const;
properties::StringListProperty _horizonsTextFiles;
properties::StringListProperty _horizonsFiles;
ghoul::lua::LuaState _state;
Timeline<glm::dvec3> _timeline;
};
+16 -1
View File
@@ -814,11 +814,26 @@ TestResult OrVerifier::operator()(const ghoul::Dictionary& dictionary,
else {
TestResult r;
r.success = false;
for (const TestResult& r2 : res) {
for (const TestResult::Offense& o : r2.offenses) {
if (o.reason != TestResult::Offense::Reason::WrongType) {
// This is the first reason that is not a wrong type, so this
// is a good candidate for a useful error message
r.offenses.push_back(o);
return r;
}
}
}
// If we got here, all of the offense reasons were a wrong type, so we
// can report that back
TestResult::Offense o = {
.offender = key,
.reason = TestResult::Offense::Reason::Verification
.reason = TestResult::Offense::Reason::WrongType
};
r.offenses.push_back(std::move(o));
return r;
}
}