Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
alterschema_error.h
1#ifndef SOURCEMETA_BLAZE_ALTERSCHEMA_ERROR_H_
2#define SOURCEMETA_BLAZE_ALTERSCHEMA_ERROR_H_
3
4#ifndef SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT
5#include <sourcemeta/blaze/alterschema_export.h>
6#endif
7
8#include <sourcemeta/core/jsonpointer.h>
9
10#include <exception> // std::exception
11#include <string> // std::string
12#include <string_view> // std::string_view
13#include <utility> // std::move
14
15namespace sourcemeta::blaze {
16
17// Exporting symbols that depends on the standard C++ library is considered
18// safe.
19// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
20#if defined(_MSC_VER)
21#pragma warning(disable : 4251 4275)
22#endif
23
26class SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT SchemaRuleMissingNameError
27 : public std::exception {
28public:
29 [[nodiscard]] auto what() const noexcept -> const char * override {
30 return "The schema rule is missing a title";
31 }
32};
33
37class SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT SchemaRuleInvalidNameError
38 : public std::exception {
39public:
40 SchemaRuleInvalidNameError(const std::string_view identifier,
41 const char *message)
42 : identifier_{identifier}, message_{message} {}
43 SchemaRuleInvalidNameError(const std::string_view identifier,
44 std::string message) = delete;
45 SchemaRuleInvalidNameError(const std::string_view identifier,
46 std::string &&message) = delete;
47 SchemaRuleInvalidNameError(const std::string_view identifier,
48 std::string_view message) = delete;
49
50 [[nodiscard]] auto what() const noexcept -> const char * override {
51 return this->message_;
52 }
53
54 [[nodiscard]] auto identifier() const noexcept -> const std::string & {
55 return this->identifier_;
56 }
57
58private:
59 std::string identifier_;
60 const char *message_;
61};
62
66class SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT SchemaRuleInvalidNamePatternError
67 : public std::exception {
68public:
69 SchemaRuleInvalidNamePatternError(const std::string_view identifier,
70 const std::string_view regex)
71 : identifier_{identifier}, regex_{regex} {}
72
73 [[nodiscard]] auto what() const noexcept -> const char * override {
74 return "The schema rule name does not match the required pattern";
75 }
76
77 [[nodiscard]] auto identifier() const noexcept -> const std::string & {
78 return this->identifier_;
79 }
80
81 [[nodiscard]] auto regex() const noexcept -> const std::string & {
82 return this->regex_;
83 }
84
85private:
86 std::string identifier_;
87 std::string regex_;
88};
89
92class SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT SchemaAbortError
93 : public std::exception {
94public:
95 SchemaAbortError(const char *message) : message_{message} {}
96 SchemaAbortError(std::string message) = delete;
97 SchemaAbortError(std::string &&message) = delete;
98 SchemaAbortError(std::string_view message) = delete;
99
100 [[nodiscard]] auto what() const noexcept -> const char * override {
101 return this->message_;
102 }
103
104private:
105 const char *message_;
106};
107
110class SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT SchemaBrokenReferenceError
111 : public std::exception {
112public:
113 SchemaBrokenReferenceError(const std::string_view identifier,
114 sourcemeta::core::Pointer schema_location,
115 const char *message)
116 : identifier_{identifier}, schema_location_{std::move(schema_location)},
117 message_{message} {}
118
119 [[nodiscard]] auto what() const noexcept -> const char * override {
120 return this->message_;
121 }
122
123 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
124 return this->identifier_;
125 }
126
127 [[nodiscard]] auto location() const noexcept
128 -> const sourcemeta::core::Pointer & {
129 return this->schema_location_;
130 }
131
132private:
133 std::string identifier_;
134 sourcemeta::core::Pointer schema_location_;
135 const char *message_;
136};
137
140class SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT SchemaTransformRuleProcessedTwiceError
141 : public std::exception {
142public:
143 SchemaTransformRuleProcessedTwiceError(const std::string_view name,
144 sourcemeta::core::Pointer location)
145 : name_{name}, location_{std::move(location)} {}
146
147 [[nodiscard]] auto what() const noexcept -> const char * override {
148 return "Transformation rules must only be processed once";
149 }
150
151 [[nodiscard]] auto name() const noexcept -> std::string_view {
152 return this->name_;
153 }
154
155 [[nodiscard]] auto location() const noexcept
156 -> const sourcemeta::core::Pointer & {
157 return this->location_;
158 }
159
160private:
161 std::string name_;
162 sourcemeta::core::Pointer location_;
163};
164
165#if defined(_MSC_VER)
166#pragma warning(default : 4251 4275)
167#endif
168
169} // namespace sourcemeta::blaze
170
171#endif
Definition alterschema_error.h:27