From 1d055261b4144dbf86b2658437015b15d4dd9bff Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 4 Sep 2022 00:32:56 +0100 Subject: initial --- .../jsoncons_ext/jsonschema/jsonschema_error.hpp | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 include/jsoncons_ext/jsonschema/jsonschema_error.hpp (limited to 'include/jsoncons_ext/jsonschema/jsonschema_error.hpp') diff --git a/include/jsoncons_ext/jsonschema/jsonschema_error.hpp b/include/jsoncons_ext/jsonschema/jsonschema_error.hpp new file mode 100644 index 0000000..7cb1061 --- /dev/null +++ b/include/jsoncons_ext/jsonschema/jsonschema_error.hpp @@ -0,0 +1,105 @@ +/// Copyright 2020 Daniel Parker +// Distributed under the Boost license, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See https://github.com/danielaparker/jsoncons for latest version + +#ifndef JSONCONS_JSONSCHEMA_JSONSCHEMA_ERROR_HPP +#define JSONCONS_JSONSCHEMA_JSONSCHEMA_ERROR_HPP + +#include +#include + +namespace jsoncons { +namespace jsonschema { + + class schema_error : public std::runtime_error, public virtual json_exception + { + public: + schema_error(const std::string& message) + : std::runtime_error(message) + { + } + + const char* what() const noexcept override + { + return std::runtime_error::what(); + } + }; + + class validation_error : public std::runtime_error, public virtual json_exception + { + public: + validation_error(const std::string& message) + : std::runtime_error(message) + { + } + + const char* what() const noexcept override + { + return std::runtime_error::what(); + } + }; + + class validation_output + { + std::string keyword_; + std::string absolute_keyword_location_; + std::string instance_location_; + std::string message_; + std::vector nested_errors_; + public: + validation_output(std::string keyword, + std::string absolute_keyword_location, + std::string instance_location, + std::string message) + : keyword_(std::move(keyword)), + absolute_keyword_location_(std::move(absolute_keyword_location)), + instance_location_(std::move(instance_location)), + message_(std::move(message)) + { + } + + validation_output(const std::string& keyword, + const std::string& absolute_keyword_location, + const std::string& instance_location, + const std::string& message, + const std::vector& nested_errors) + : keyword_(keyword), + absolute_keyword_location_(absolute_keyword_location), + instance_location_(instance_location), + message_(message), + nested_errors_(nested_errors) + { + } + + const std::string& instance_location() const + { + return instance_location_; + } + + const std::string& message() const + { + return message_; + } + + const std::string& absolute_keyword_location() const + { + return absolute_keyword_location_; + } + + const std::string& keyword() const + { + return keyword_; + } + + const std::vector& nested_errors() const + { + return nested_errors_; + } + }; + +} // namespace jsonschema +} // namespace jsoncons + +#endif // JSONCONS_JSONSCHEMA_JSONSCHEMA_ERROR_HPP -- cgit v1.2.3