Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
jsonschema_error.h
1#ifndef SOURCEMETA_CORE_JSONSCHEMA_ERROR_H
2#define SOURCEMETA_CORE_JSONSCHEMA_ERROR_H
3
4#ifndef SOURCEMETA_CORE_JSONSCHEMA_EXPORT
5#include <sourcemeta/core/jsonschema_export.h>
6#endif
7
8#include <sourcemeta/core/jsonpointer.h>
9
10#include <cstdint> // std::uint64_t
11#include <exception> // std::exception
12#include <string> // std::string
13#include <string_view> // std::string_view
14
15namespace sourcemeta::core {
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_CORE_JSONSCHEMA_EXPORT SchemaError : public std::exception {
27public:
29 SchemaError(const char *message) : message_{message} {}
30 SchemaError(std::string message) = delete;
31 SchemaError(std::string &&message) = delete;
32 SchemaError(std::string_view message) = delete;
33
34 [[nodiscard]] auto what() const noexcept -> const char * override {
35 return this->message_;
36 }
37
38private:
39 const char *message_;
40};
41
44class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaResolutionError
45 : public std::exception {
46public:
48 SchemaResolutionError(const std::string_view identifier, const char *message)
49 : identifier_{identifier}, message_{message} {}
50
51 [[nodiscard]] auto what() const noexcept -> const char * override {
52 return this->message_;
53 }
54
56 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
57 return this->identifier_;
58 }
59
60private:
61 std::string identifier_;
62 const char *message_;
63};
64
69class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaRelativeMetaschemaResolutionError
70 : public SchemaResolutionError {
71public:
75 "Relative meta-schema URIs are not valid "
76 "according to the JSON Schema specification"} {}
77};
78
81class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaVocabularyError
82 : public std::exception {
83public:
85 SchemaVocabularyError(const std::string_view uri, const char *message)
86 : uri_{uri}, message_{message} {}
87
88 [[nodiscard]] auto what() const noexcept -> const char * override {
89 return this->message_;
90 }
91
93 [[nodiscard]] auto uri() const noexcept -> std::string_view {
94 return this->uri_;
95 }
96
97private:
98 std::string uri_;
99 const char *message_;
100};
101
104class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaReferenceError
105 : public std::exception {
106public:
108 SchemaReferenceError(const std::string_view identifier,
109 sourcemeta::core::Pointer schema_location,
110 const char *message)
111 : identifier_{identifier}, schema_location_{std::move(schema_location)},
112 message_{message} {}
113
114 [[nodiscard]] auto what() const noexcept -> const char * override {
115 return this->message_;
116 }
117
119 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
120 return this->identifier_;
121 }
122
125 [[nodiscard]] auto location() const noexcept
126 -> const sourcemeta::core::Pointer & {
127 return this->schema_location_;
128 }
129
130private:
131 std::string identifier_;
132 sourcemeta::core::Pointer schema_location_;
133 const char *message_;
134};
135
138class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaUnknownDialectError
139 : public std::exception {
140public:
141 SchemaUnknownDialectError() = default;
142
143 [[nodiscard]] auto what() const noexcept -> const char * override {
144 return "Could not determine the dialect of the schema";
145 }
146};
147
151class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaUnknownBaseDialectError
152 : public std::exception {
153public:
154 SchemaUnknownBaseDialectError() = default;
155
156 [[nodiscard]] auto what() const noexcept -> const char * override {
157 return "Could not determine the base dialect of the schema";
158 }
159};
160
164class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaReferenceObjectResourceError
165 : public std::exception {
166public:
169 : identifier_{identifier} {}
170
171 [[nodiscard]] auto what() const noexcept -> const char * override {
172 return "A schema with a top-level `$ref` in JSON Schema Draft 7 and older "
173 "dialects ignores every sibling keywords (like identifiers and "
174 "meta-schema declarations) and therefore many operations, like "
175 "bundling, are not possible without undefined behavior";
176 }
177
179 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
180 return this->identifier_;
181 }
182
183private:
184 std::string identifier_;
185};
186
189class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaKeywordError
190 : public std::exception {
191public:
193 SchemaKeywordError(const std::string_view keyword,
194 const std::string_view value, const char *message)
195 : keyword_{keyword}, value_{value}, message_{message} {}
196
197 [[nodiscard]] auto what() const noexcept -> const char * override {
198 return this->message_;
199 }
200
202 [[nodiscard]] auto value() const noexcept -> std::string_view {
203 return this->value_;
204 }
205
207 [[nodiscard]] auto keyword() const noexcept -> std::string_view {
208 return this->keyword_;
209 }
210
211private:
212 std::string keyword_;
213 std::string value_;
214 const char *message_;
215};
216
219class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrameError
220 : public std::exception {
221public:
223 SchemaFrameError(const std::string_view identifier, const char *message)
224 : identifier_{identifier}, message_{message} {}
225
226 [[nodiscard]] auto what() const noexcept -> const char * override {
227 return this->message_;
228 }
229
231 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
232 return this->identifier_;
233 }
234
235private:
236 std::string identifier_;
237 const char *message_;
238};
239
243class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrameLimitError
244 : public std::exception {
245public:
247 SchemaFrameLimitError(const std::uint64_t limit) : limit_{limit} {}
248
249 [[nodiscard]] auto what() const noexcept -> const char * override {
250 return "The schema exceeds the maximum number of frame locations";
251 }
252
254 [[nodiscard]] auto limit() const noexcept -> std::uint64_t {
255 return this->limit_;
256 }
257
258private:
259 std::uint64_t limit_;
260};
261
264class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaAnchorCollisionError
265 : public std::exception {
266public:
271 : identifier_{identifier}, location_(std::move(location)),
272 other_(std::move(other)) {}
273
274 [[nodiscard]] auto what() const noexcept -> const char * override {
275 return "Schema anchor already exists";
276 }
277
279 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
280 return this->identifier_;
281 }
282
285 [[nodiscard]] auto location() const noexcept
286 -> const sourcemeta::core::Pointer & {
287 return this->location_;
288 }
289
291 [[nodiscard]] auto other() const noexcept
292 -> const sourcemeta::core::Pointer & {
293 return this->other_;
294 }
295
296private:
297 std::string identifier_;
300};
301
302#if defined(_MSC_VER)
303#pragma warning(default : 4251 4275)
304#endif
305
306} // namespace sourcemeta::core
307
308#endif
GenericPointer< JSON::String, PropertyHashJSON< JSON::String > > Pointer
Definition jsonpointer.h:39
auto uri() const noexcept -> std::string_view
The vocabulary that caused the error.
Definition jsonschema_error.h:93
SchemaKeywordError(const std::string_view keyword, const std::string_view value, const char *message)
Create a keyword error.
Definition jsonschema_error.h:193
SchemaVocabularyError(const std::string_view uri, const char *message)
Create a vocabulary error.
Definition jsonschema_error.h:85
auto limit() const noexcept -> std::uint64_t
The maximum number of locations that framing was allowed to register.
Definition jsonschema_error.h:254
auto identifier() const noexcept -> std::string_view
The anchor that collided.
Definition jsonschema_error.h:279
SchemaRelativeMetaschemaResolutionError(const std::string_view identifier)
Create a relative meta-schema resolution error.
Definition jsonschema_error.h:73
SchemaFrameError(const std::string_view identifier, const char *message)
Create a framing error.
Definition jsonschema_error.h:223
SchemaError(const char *message)
Create a general schema error.
Definition jsonschema_error.h:29
auto keyword() const noexcept -> std::string_view
The keyword that caused the error.
Definition jsonschema_error.h:207
auto value() const noexcept -> std::string_view
The value that caused the error.
Definition jsonschema_error.h:202
SchemaFrameLimitError(const std::uint64_t limit)
Create a framing limit error.
Definition jsonschema_error.h:247
SchemaReferenceObjectResourceError(const std::string_view identifier)
Create a reference object resource error.
Definition jsonschema_error.h:168
auto identifier() const noexcept -> std::string_view
The reference that caused the error.
Definition jsonschema_error.h:179
SchemaResolutionError(const std::string_view identifier, const char *message)
Create a schema resolution error.
Definition jsonschema_error.h:48
SchemaReferenceError(const std::string_view identifier, sourcemeta::core::Pointer schema_location, const char *message)
Create a reference error.
Definition jsonschema_error.h:108
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition jsonschema_error.h:285
auto identifier() const noexcept -> std::string_view
The identifier of the schema that caused the error.
Definition jsonschema_error.h:231
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition jsonschema_error.h:125
auto other() const noexcept -> const sourcemeta::core::Pointer &
The other place that declares the same anchor.
Definition jsonschema_error.h:291
auto identifier() const noexcept -> std::string_view
The identifier that could not be resolved.
Definition jsonschema_error.h:56
auto identifier() const noexcept -> std::string_view
The reference that caused the error.
Definition jsonschema_error.h:119
SchemaAnchorCollisionError(const std::string_view identifier, sourcemeta::core::Pointer location, sourcemeta::core::Pointer other)
Create an anchor collision error.
Definition jsonschema_error.h:268
Definition jsonschema_error.h:26