Skip to content

Commit 1b27d5c

Browse files
bluescarnipboettch
authored andcommittedSep 3, 2022
Increase the verbosity of the error message produced when there are undefined references.
1 parent 0efd3ae commit 1b27d5c

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed
 

‎src/json-validator.cpp

+26-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <memory>
1515
#include <set>
1616
#include <sstream>
17+
#include <string>
1718

1819
using nlohmann::json;
1920
using nlohmann::json_patch;
@@ -308,11 +309,31 @@ class root_schema
308309
break;
309310
} while (1);
310311

311-
for (const auto &file : files_)
312-
if (file.second.unresolved.size() != 0)
312+
for (const auto &file : files_) {
313+
if (file.second.unresolved.size() != 0) {
314+
// Build a representation of the undefined
315+
// references as a list of comma-separated strings.
316+
auto n_urefs = file.second.unresolved.size();
317+
std::string urefs = "[";
318+
319+
decltype(n_urefs) counter = 0;
320+
for (const auto &p : file.second.unresolved) {
321+
urefs += p.first;
322+
323+
if (counter != n_urefs - 1u) {
324+
urefs += ", ";
325+
}
326+
327+
++counter;
328+
}
329+
330+
urefs += "]";
331+
313332
throw std::invalid_argument("after all files have been parsed, '" +
314333
(file.first == "" ? "<root>" : file.first) +
315-
"' has still undefined references.");
334+
"' has still the following undefined references: " + urefs);
335+
}
336+
}
316337
}
317338

318339
void validate(const json::json_pointer &ptr,
@@ -929,8 +950,8 @@ class boolean : public schema
929950
{
930951
if (!true_) { // false schema
931952
// empty array
932-
//switch (instance.type()) {
933-
//case json::value_t::array:
953+
// switch (instance.type()) {
954+
// case json::value_t::array:
934955
// if (instance.size() != 0) // valid false-schema
935956
// e.error(ptr, instance, "false-schema required empty array");
936957
// return;

‎test/issue-98.cpp

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

0 commit comments

Comments
 (0)
Please sign in to comment.