Increase the verbosity of the error message produced when there are undefined references.

This commit is contained in:
Francesco Biscani 2022-06-21 11:13:25 +02:00 committed by Patrick Boettcher
parent 0efd3ae507
commit 1b27d5cf01
2 changed files with 28 additions and 6 deletions

View File

@ -14,6 +14,7 @@
#include <memory>
#include <set>
#include <sstream>
#include <string>
using nlohmann::json;
using nlohmann::json_patch;
@ -308,11 +309,31 @@ public:
break;
} while (1);
for (const auto &file : files_)
if (file.second.unresolved.size() != 0)
for (const auto &file : files_) {
if (file.second.unresolved.size() != 0) {
// Build a representation of the undefined
// references as a list of comma-separated strings.
auto n_urefs = file.second.unresolved.size();
std::string urefs = "[";
decltype(n_urefs) counter = 0;
for (const auto &p : file.second.unresolved) {
urefs += p.first;
if (counter != n_urefs - 1u) {
urefs += ", ";
}
++counter;
}
urefs += "]";
throw std::invalid_argument("after all files have been parsed, '" +
(file.first == "" ? "<root>" : file.first) +
"' has still undefined references.");
"' has still the following undefined references: " + urefs);
}
}
}
void validate(const json::json_pointer &ptr,

View File

@ -8,7 +8,8 @@ int main(void)
try {
validator.set_root_schema(nlBase); // this line will log the caught exception
} catch (const std::exception &e) {
if (std::string("after all files have been parsed, '<root>' has still undefined references.") == e.what())
if (std::string("after all files have been parsed, '<root>' has still the following undefined references: [/unknown/keywords]") == e.what())
return EXIT_SUCCESS;
}
return EXIT_FAILURE;