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/error.h>
9#include <sourcemeta/core/jsonpointer.h>
10
11#include <cstdint> // std::uint64_t
12#include <string> // std::string
13#include <string_view> // std::string_view
14
15namespace sourcemeta::core {
16
17SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
18
21class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaError : public Error {
22public:
25
26private:
27};
28
31class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaResolutionError : public Error {
32public:
35 const std::string_view identifier)
36 : Error{message}, identifier_{identifier} {}
37
39 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
40 return this->identifier_;
41 }
42
43private:
44 std::string identifier_;
45};
46
51class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaRelativeMetaschemaResolutionError
52 : public SchemaResolutionError {
53public:
56 : SchemaResolutionError{"Relative meta-schema URIs are not valid "
57 "according to the JSON Schema specification",
58 identifier} {}
59};
60
63class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaVocabularyError : public Error {
64public:
66 SchemaVocabularyError(const StaticString message, const std::string_view uri)
67 : Error{message}, uri_{uri} {}
68
70 [[nodiscard]] auto uri() const noexcept -> std::string_view {
71 return this->uri_;
72 }
73
74private:
75 std::string uri_;
76};
77
80class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaReferenceError : public Error {
81public:
84 const std::string_view identifier,
85 sourcemeta::core::Pointer schema_location)
86 : Error{message}, identifier_{identifier},
87 schema_location_{std::move(schema_location)} {}
88
90 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
91 return this->identifier_;
92 }
93
96 [[nodiscard]] auto location() const noexcept
97 -> const sourcemeta::core::Pointer & {
98 return this->schema_location_;
99 }
100
101private:
102 std::string identifier_;
103 sourcemeta::core::Pointer schema_location_;
104};
105
108class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaUnknownDialectError
109 : public Error {
110public:
111 SchemaUnknownDialectError() noexcept
112 : Error{"Could not determine the dialect of the schema"} {}
113};
114
118class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaUnknownBaseDialectError
119 : public Error {
120public:
121 SchemaUnknownBaseDialectError() noexcept
122 : Error{"Could not determine the base dialect of the schema"} {}
123};
124
128class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaReferenceObjectResourceError
129 : public Error {
130public:
133 : Error{"A schema with a top-level `$ref` in JSON Schema Draft 7 and "
134 "older dialects ignores every sibling keywords (like "
135 "identifiers and meta-schema declarations) and therefore many "
136 "operations, like bundling, are not possible without undefined "
137 "behavior"},
138 identifier_{identifier} {}
139
141 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
142 return this->identifier_;
143 }
144
145private:
146 std::string identifier_;
147};
148
155class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaDialectImpossibleError
156 : public Error {
157public:
159 SchemaDialectImpossibleError(const std::string_view keyword,
160 const std::string_view dialect,
161 sourcemeta::core::Pointer schema_location)
162 : Error{"The dialect that this schema declares does not define the "
163 "keyword that declares it"},
164 keyword_{keyword}, dialect_{dialect},
165 schema_location_{std::move(schema_location)} {}
166
168 [[nodiscard]] auto keyword() const noexcept -> std::string_view {
169 return this->keyword_;
170 }
171
173 [[nodiscard]] auto dialect() const noexcept -> std::string_view {
174 return this->dialect_;
175 }
176
179 [[nodiscard]] auto location() const noexcept
180 -> const sourcemeta::core::Pointer & {
181 return this->schema_location_;
182 }
183
184private:
185 std::string keyword_;
186 std::string dialect_;
187 sourcemeta::core::Pointer schema_location_;
188};
189
192class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaKeywordError : public Error {
193public:
195 SchemaKeywordError(const StaticString message, const std::string_view keyword,
196 const std::string_view value)
197 : Error{message}, keyword_{keyword}, value_{value} {}
198
200 [[nodiscard]] auto value() const noexcept -> std::string_view {
201 return this->value_;
202 }
203
205 [[nodiscard]] auto keyword() const noexcept -> std::string_view {
206 return this->keyword_;
207 }
208
209private:
210 std::string keyword_;
211 std::string value_;
212};
213
217class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaContainerError : public Error {
218public:
223
226 [[nodiscard]] auto location() const noexcept
227 -> const sourcemeta::core::Pointer & {
228 return this->location_;
229 }
230
231private:
233};
234
237class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrameError : public Error {
238public:
241 const std::string_view identifier)
242 : Error{message}, identifier_{identifier} {}
243
245 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
246 return this->identifier_;
247 }
248
249private:
250 std::string identifier_;
251};
252
256class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrameLimitError : public Error {
257public:
259 SchemaFrameLimitError(const std::uint64_t limit) noexcept
260 : Error{"The schema exceeds the maximum number of frame locations"},
261 limit_{limit} {}
262
264 [[nodiscard]] auto limit() const noexcept -> std::uint64_t {
265 return this->limit_;
266 }
267
268private:
269 std::uint64_t limit_;
270};
271
274class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaAnchorCollisionError
275 : public Error {
276public:
281 : Error{"Schema anchor already exists"}, identifier_{identifier},
282 location_(std::move(location)), other_(std::move(other)) {}
283
285 [[nodiscard]] auto identifier() const noexcept -> std::string_view {
286 return this->identifier_;
287 }
288
291 [[nodiscard]] auto location() const noexcept
292 -> const sourcemeta::core::Pointer & {
293 return this->location_;
294 }
295
297 [[nodiscard]] auto other() const noexcept
298 -> const sourcemeta::core::Pointer & {
299 return this->other_;
300 }
301
302private:
303 std::string identifier_;
306};
307
308SOURCEMETA_CORE_ERROR_WARNINGS_POP
309
310} // namespace sourcemeta::core
311
312#endif
auto message() const noexcept -> StaticString
Definition error_base.h:78
Error(const StaticString message) noexcept
Construct the error given its message.
Definition error_base.h:84
GenericPointer< JSON::String, PropertyHashJSON< JSON::String > > Pointer
Definition jsonpointer.h:41
auto uri() const noexcept -> std::string_view
The vocabulary that caused the error.
Definition jsonschema_error.h:70
SchemaKeywordError(const StaticString message, const std::string_view keyword, const std::string_view value)
Create a keyword error.
Definition jsonschema_error.h:195
auto limit() const noexcept -> std::uint64_t
The maximum number of locations that framing was allowed to register.
Definition jsonschema_error.h:264
SchemaResolutionError(const StaticString message, const std::string_view identifier)
Create a schema resolution error.
Definition jsonschema_error.h:34
SchemaFrameLimitError(const std::uint64_t limit) noexcept
Create a framing limit error.
Definition jsonschema_error.h:259
auto identifier() const noexcept -> std::string_view
The anchor that collided.
Definition jsonschema_error.h:285
SchemaRelativeMetaschemaResolutionError(const std::string_view identifier)
Create a relative meta-schema resolution error.
Definition jsonschema_error.h:55
SchemaVocabularyError(const StaticString message, const std::string_view uri)
Create a vocabulary error.
Definition jsonschema_error.h:66
auto keyword() const noexcept -> std::string_view
The keyword that caused the error.
Definition jsonschema_error.h:205
auto value() const noexcept -> std::string_view
The value that caused the error.
Definition jsonschema_error.h:200
SchemaError(const StaticString message) noexcept
Create a general schema error.
Definition jsonschema_error.h:24
SchemaReferenceError(const StaticString message, const std::string_view identifier, sourcemeta::core::Pointer schema_location)
Create a reference error.
Definition jsonschema_error.h:83
SchemaReferenceObjectResourceError(const std::string_view identifier)
Create a reference object resource error.
Definition jsonschema_error.h:132
auto keyword() const noexcept -> std::string_view
The keyword that names the dialect.
Definition jsonschema_error.h:168
auto identifier() const noexcept -> std::string_view
The reference that caused the error.
Definition jsonschema_error.h:141
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition jsonschema_error.h:291
auto identifier() const noexcept -> std::string_view
The identifier of the schema that caused the error.
Definition jsonschema_error.h:245
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition jsonschema_error.h:96
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition jsonschema_error.h:226
auto dialect() const noexcept -> std::string_view
The dialect that the schema names.
Definition jsonschema_error.h:173
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition jsonschema_error.h:179
auto other() const noexcept -> const sourcemeta::core::Pointer &
The other place that declares the same anchor.
Definition jsonschema_error.h:297
SchemaFrameError(const StaticString message, const std::string_view identifier)
Create a framing error.
Definition jsonschema_error.h:240
auto identifier() const noexcept -> std::string_view
The identifier that could not be resolved.
Definition jsonschema_error.h:39
SchemaDialectImpossibleError(const std::string_view keyword, const std::string_view dialect, sourcemeta::core::Pointer schema_location)
Create a dialect impossibility error.
Definition jsonschema_error.h:159
SchemaContainerError(const StaticString message, sourcemeta::core::Pointer location)
Create a container error.
Definition jsonschema_error.h:220
auto identifier() const noexcept -> std::string_view
The reference that caused the error.
Definition jsonschema_error.h:90
SchemaAnchorCollisionError(const std::string_view identifier, sourcemeta::core::Pointer location, sourcemeta::core::Pointer other)
Create an anchor collision error.
Definition jsonschema_error.h:278
Definition text_static_string.h:20