Browse Source

refactor: some cleanup around exceptions

Sam Jaffe 1 year ago
parent
commit
535177cbf8
3 changed files with 8 additions and 3 deletions
  1. 1 1
      Makefile
  2. 3 2
      include/jvalidate/detail/reference_manager.h
  3. 4 0
      include/jvalidate/schema.h

+ 1 - 1
Makefile

@@ -11,7 +11,7 @@ CXX := clang++
 
 CXX_FLAGS := -Wall -Wextra -Werror -std=c++20 \
 	     -isystem include/ -I/opt/homebrew/opt/icu4c/include \
-	     -DJVALIDATE_USE_EXCEPTIONS
+	     -DJVALIDATE_USE_EXCEPTIONS -DJVALIDATE_LOAD_FAILURE_AS_FALSE_SCHEMA
 
 LD_FLAGS := -L/opt/local/lib -L/opt/homebrew/opt/icu4c/lib -licuuc
 

+ 3 - 2
include/jvalidate/detail/reference_manager.h

@@ -4,6 +4,7 @@
 #include <map>
 #include <set>
 #include <unordered_map>
+#include <unordered_set>
 
 #include <jvalidate/detail/anchor.h>
 #include <jvalidate/detail/dynamic_reference_context.h>
@@ -19,7 +20,6 @@
 #include <jvalidate/enum.h>
 #include <jvalidate/forward.h>
 #include <jvalidate/uri.h>
-#include <unordered_set>
 
 namespace jvalidate::detail {
 template <Adapter A> class ReferenceManager {
@@ -75,7 +75,8 @@ public:
     EXPECT_M(external->type() == adapter::Type::Object, "meta-schema must be an object");
 
     auto metaschema = external->as_object();
-    EXPECT_M(metaschema.contains("$schema"), "meta-schema must reference an");
+    EXPECT_M(metaschema.contains("$schema"),
+             "user-defined meta-schema must reference a base schema");
 
     // Initialize first to prevent recursion
     Vocabulary<A> & parent = user_vocabularies_[schema];

+ 4 - 0
include/jvalidate/schema.h

@@ -190,7 +190,11 @@ private:
     }
 
     std::string error = "URIResolver could not resolve " + std::string(lexical.uri());
+#ifdef JVALIDATE_LOAD_FAILURE_AS_FALSE_SCHEMA
     return alias(dynamic, &cache_.try_emplace(dynamic, error).first->second);
+#else
+    JVALIDATE_THROW(std::runtime_error, error);
+#endif
   }
 
   template <Adapter A> schema::Node const * fetch_schema(detail::ParserContext<A> const & context) {