Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
compiler_error.h
1#ifndef SOURCEMETA_BLAZE_COMPILER_ERROR_H
2#define SOURCEMETA_BLAZE_COMPILER_ERROR_H
3
4#ifndef SOURCEMETA_BLAZE_COMPILER_EXPORT
5#include <sourcemeta/blaze/compiler_export.h>
6#endif
7
8#include <sourcemeta/core/jsonpointer.h>
9#include <sourcemeta/core/uri.h>
10
11#include <cstdint> // std::uint64_t
12#include <exception> // std::exception
13#include <string> // std::string
14#include <string_view> // std::string_view
15#include <utility> // std::move
16
17namespace sourcemeta::blaze {
18
19// Exporting symbols that depends on the standard C++ library is considered
20// safe.
21// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
22#if defined(_MSC_VER)
23#pragma warning(disable : 4251 4275)
24#endif
25
28class SOURCEMETA_BLAZE_COMPILER_EXPORT CompilerError : public std::exception {
29public:
30 CompilerError(sourcemeta::core::URI base,
31 sourcemeta::core::Pointer schema_location, const char *message)
32 : base_{std::move(base)}, schema_location_{std::move(schema_location)},
33 message_{message} {}
34 CompilerError(sourcemeta::core::URI base,
35 sourcemeta::core::Pointer schema_location,
36 std::string message) = delete;
37 CompilerError(sourcemeta::core::URI base,
38 sourcemeta::core::Pointer schema_location,
39 std::string &&message) = delete;
40 CompilerError(sourcemeta::core::URI base,
41 sourcemeta::core::Pointer schema_location,
42 std::string_view message) = delete;
43 [[nodiscard]] auto what() const noexcept -> const char * override {
44 return this->message_;
45 }
46
47 [[nodiscard]] auto base() const noexcept -> const sourcemeta::core::URI & {
48 return this->base_;
49 }
50
53 [[nodiscard]] auto location() const noexcept
54 -> const sourcemeta::core::Pointer & {
55 return this->schema_location_;
56 }
57
58private:
59 sourcemeta::core::URI base_;
60 sourcemeta::core::Pointer schema_location_;
61 const char *message_;
62};
63
66class SOURCEMETA_BLAZE_COMPILER_EXPORT CompilerInvalidRegexError
67 : public std::exception {
68public:
69 CompilerInvalidRegexError(sourcemeta::core::URI base,
70 sourcemeta::core::Pointer schema_location,
71 std::string regex)
72 : base_{std::move(base)}, schema_location_{std::move(schema_location)},
73 regex_{std::move(regex)} {}
74 [[nodiscard]] auto what() const noexcept -> const char * override {
75 return "Invalid regular expression";
76 }
77
78 [[nodiscard]] auto base() const noexcept -> const sourcemeta::core::URI & {
79 return this->base_;
80 }
81
84 [[nodiscard]] auto location() const noexcept
85 -> const sourcemeta::core::Pointer & {
86 return this->schema_location_;
87 }
88
89 [[nodiscard]] auto regex() const noexcept -> const std::string & {
90 return this->regex_;
91 }
92
93private:
94 sourcemeta::core::URI base_;
95 sourcemeta::core::Pointer schema_location_;
96 std::string regex_;
97};
98
101class SOURCEMETA_BLAZE_COMPILER_EXPORT CompilerReferenceTargetNotSchemaError
102 : public std::exception {
103public:
104 CompilerReferenceTargetNotSchemaError(
105 const std::string_view identifier,
106 sourcemeta::core::Pointer schema_location)
107 : identifier_{identifier}, schema_location_{std::move(schema_location)} {}
108
109 [[nodiscard]] auto what() const noexcept -> const char * override {
110 return "The referenced schema is not considered to be a valid subschema "
111 "given the dialect and vocabularies in use";
112 }
113
114 [[nodiscard]] auto identifier() const noexcept -> const std::string & {
115 return this->identifier_;
116 }
117
120 [[nodiscard]] auto location() const noexcept
121 -> const sourcemeta::core::Pointer & {
122 return this->schema_location_;
123 }
124
125private:
126 std::string identifier_;
127 sourcemeta::core::Pointer schema_location_;
128};
129
133class SOURCEMETA_BLAZE_COMPILER_EXPORT CompilerInstructionLimitError
134 : public std::exception {
135public:
136 CompilerInstructionLimitError(const std::uint64_t limit) : limit_{limit} {}
137
138 [[nodiscard]] auto what() const noexcept -> const char * override {
139 return "The schema exceeds the maximum number of compiled instructions";
140 }
141
143 [[nodiscard]] auto limit() const noexcept -> std::uint64_t {
144 return this->limit_;
145 }
146
147private:
148 std::uint64_t limit_;
149};
150
154class SOURCEMETA_BLAZE_COMPILER_EXPORT CompilerDepthLimitError
155 : public std::exception {
156public:
157 CompilerDepthLimitError(const std::uint64_t limit) : limit_{limit} {}
158
159 [[nodiscard]] auto what() const noexcept -> const char * override {
160 return "The schema exceeds the maximum compilation depth";
161 }
162
164 [[nodiscard]] auto limit() const noexcept -> std::uint64_t {
165 return this->limit_;
166 }
167
168private:
169 std::uint64_t limit_;
170};
171
174class SOURCEMETA_BLAZE_COMPILER_EXPORT CompilerInvalidEntryPoint
175 : public std::exception {
176public:
177 CompilerInvalidEntryPoint(const std::string_view entrypoint,
178 const char *message)
179 : identifier_{entrypoint}, message_{message} {}
180 CompilerInvalidEntryPoint(const std::string_view entrypoint,
181 std::string message) = delete;
182 CompilerInvalidEntryPoint(const std::string_view entrypoint,
183 std::string &&message) = delete;
184 CompilerInvalidEntryPoint(const std::string_view entrypoint,
185 std::string_view message) = delete;
186
187 [[nodiscard]] auto what() const noexcept -> const char * override {
188 return this->message_;
189 }
190
191 [[nodiscard]] auto identifier() const noexcept -> const std::string & {
192 return this->identifier_;
193 }
194
195private:
196 std::string identifier_;
197 const char *message_;
198};
199
200#if defined(_MSC_VER)
201#pragma warning(default : 4251 4275)
202#endif
203
204} // namespace sourcemeta::blaze
205
206#endif
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition compiler_error.h:53
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition compiler_error.h:120
auto location() const noexcept -> const sourcemeta::core::Pointer &
Definition compiler_error.h:84
auto limit() const noexcept -> std::uint64_t
The deepest that compilation was allowed to descend.
Definition compiler_error.h:164
auto limit() const noexcept -> std::uint64_t
The maximum number of instructions that compilation was allowed to make.
Definition compiler_error.h:143