fix #98: catch out-of-range-exception only
Leave other exception go through - real errors.
This commit is contained in:
parent
940262ceae
commit
81eba4928d
@ -178,11 +178,13 @@ public:
|
||||
|
||||
// referencing an unknown keyword, turn it into schema
|
||||
try {
|
||||
auto &subschema = file.unknown_keywords.at(uri.pointer());
|
||||
auto s = schema::make(subschema, this, {}, {{uri}});
|
||||
file.unknown_keywords.erase(uri.fragment());
|
||||
return s;
|
||||
} catch (...) {
|
||||
auto &subschema = file.unknown_keywords.at(uri.pointer()); // null is returned if not existing
|
||||
auto s = schema::make(subschema, this, {}, {{uri}}); // A JSON Schema MUST be an object or a boolean.
|
||||
if (s) { // nullptr if invalid schema, e.g. null
|
||||
file.unknown_keywords.erase(uri.fragment());
|
||||
return s;
|
||||
}
|
||||
} catch (nlohmann::detail::out_of_range &) { // at() did not find it
|
||||
}
|
||||
|
||||
// get or create a schema_ref
|
||||
|
||||
@ -39,6 +39,10 @@ add_executable(issue-25-default-values issue-25-default-values.cpp)
|
||||
target_link_libraries(issue-25-default-values nlohmann_json_schema_validator)
|
||||
add_test(NAME issue-25-default-values COMMAND issue-25-default-values)
|
||||
|
||||
add_executable(issue-98 issue-98.cpp)
|
||||
target_link_libraries(issue-98 nlohmann_json_schema_validator)
|
||||
add_test(NAME issue-98-erase-exception-unknown-keywords COMMAND issue-98)
|
||||
|
||||
# Unit test for string format checks
|
||||
add_executable("string-format-check-test" "string-format-check-test.cpp")
|
||||
target_include_directories("string-format-check-test" PRIVATE "${PROJECT_SOURCE_DIR}/src/")
|
||||
|
||||
10
test/issue-98.cpp
Normal file
10
test/issue-98.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
nlohmann::json nlBase{{"$ref", "#/unknown/keywords"}};
|
||||
nlohmann::json_schema::json_validator validator;
|
||||
validator.set_root_schema(nlBase); // this line will log the caught exception
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user