Increase the verbosity of the error message produced when there are undefined references.
This commit is contained in:
parent
0efd3ae507
commit
1b27d5cf01
@ -14,6 +14,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
using nlohmann::json_patch;
|
using nlohmann::json_patch;
|
||||||
@ -308,11 +309,31 @@ public:
|
|||||||
break;
|
break;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
for (const auto &file : files_)
|
for (const auto &file : files_) {
|
||||||
if (file.second.unresolved.size() != 0)
|
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, '" +
|
throw std::invalid_argument("after all files have been parsed, '" +
|
||||||
(file.first == "" ? "<root>" : file.first) +
|
(file.first == "" ? "<root>" : file.first) +
|
||||||
"' has still undefined references.");
|
"' has still the following undefined references: " + urefs);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void validate(const json::json_pointer &ptr,
|
void validate(const json::json_pointer &ptr,
|
||||||
@ -929,8 +950,8 @@ class boolean : public schema
|
|||||||
{
|
{
|
||||||
if (!true_) { // false schema
|
if (!true_) { // false schema
|
||||||
// empty array
|
// empty array
|
||||||
//switch (instance.type()) {
|
// switch (instance.type()) {
|
||||||
//case json::value_t::array:
|
// case json::value_t::array:
|
||||||
// if (instance.size() != 0) // valid false-schema
|
// if (instance.size() != 0) // valid false-schema
|
||||||
// e.error(ptr, instance, "false-schema required empty array");
|
// e.error(ptr, instance, "false-schema required empty array");
|
||||||
// return;
|
// return;
|
||||||
|
|||||||
@ -8,7 +8,8 @@ int main(void)
|
|||||||
try {
|
try {
|
||||||
validator.set_root_schema(nlBase); // this line will log the caught exception
|
validator.set_root_schema(nlBase); // this line will log the caught exception
|
||||||
} catch (const std::exception &e) {
|
} 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_SUCCESS;
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user