Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
uritemplate_error.h
1#ifndef SOURCEMETA_CORE_URITEMPLATE_ERROR_H_
2#define SOURCEMETA_CORE_URITEMPLATE_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_URITEMPLATE_EXPORT
5#include <sourcemeta/core/uritemplate_export.h>
6#endif
7
8#include <sourcemeta/core/error.h>
9
10#include <cstdint> // std::uint64_t
11#include <filesystem> // std::filesystem::path
12#include <string> // std::string
13#include <string_view> // std::string_view
14#include <utility> // std::move
15
16namespace sourcemeta::core {
17
18SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
19
22class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateParseError : public Error {
23public:
25 URITemplateParseError(const std::uint64_t column) noexcept
26 : Error{"The input is not a valid URI Template"}, column_{column} {}
27
29 [[nodiscard]] auto column() const noexcept -> std::uint64_t {
30 return this->column_;
31 }
32
33private:
34 std::uint64_t column_;
35};
36
39class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateExpansionError
40 : public Error {
41public:
45};
46
49class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateRouterVariableMismatchError
50 : public Error {
51public:
54 const std::string_view right)
55 : Error{"Variable name mismatch when adding route"}, left_{left},
56 right_{right} {}
57
59 [[nodiscard]] auto left() const noexcept -> const std::string & {
60 return this->left_;
61 }
62
64 [[nodiscard]] auto right() const noexcept -> const std::string & {
65 return this->right_;
66 }
67
68private:
69 std::string left_;
70 std::string right_;
71};
72
75class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateRouterInvalidSegmentError
76 : public Error {
77public:
80 const std::string_view segment)
81 : Error{message}, segment_{segment} {}
82
84 [[nodiscard]] auto segment() const noexcept -> const std::string & {
85 return this->segment_;
86 }
87
88private:
89 std::string segment_;
90};
91
95class SOURCEMETA_CORE_URITEMPLATE_EXPORT
97public:
100 : Error{"Invalid operation identifier"}, operation_id_{operation_id} {}
101
103 [[nodiscard]] auto operation_id() const noexcept -> const std::string & {
104 return this->operation_id_;
105 }
106
107private:
108 std::string operation_id_;
109};
110
114class SOURCEMETA_CORE_URITEMPLATE_EXPORT
116public:
119 const std::string_view operation_id)
120 : Error{"Duplicate operation identifier"}, operation_id_{operation_id} {}
121
123 [[nodiscard]] auto operation_id() const noexcept -> const std::string & {
124 return this->operation_id_;
125 }
126
127private:
128 std::string operation_id_;
129};
130
133class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateRouterSaveError
134 : public Error {
135public:
138 std::filesystem::path path)
139 : Error{message}, path_{std::move(path)} {}
140
142 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
143 return this->path_;
144 }
145
146private:
147 std::filesystem::path path_;
148};
149
152class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateRouterReadError
153 : public Error {
154public:
156 URITemplateRouterReadError(std::filesystem::path path)
157 : Error{"Failed to open router file for reading"},
158 path_{std::move(path)} {}
159
161 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
162 return this->path_;
163 }
164
165private:
166 std::filesystem::path path_;
167};
168
169SOURCEMETA_CORE_ERROR_WARNINGS_POP
170
171} // namespace sourcemeta::core
172
173#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
Definition text_static_string.h:20
auto segment() const noexcept -> const std::string &
Get the offending segment.
Definition uritemplate_error.h:84
auto operation_id() const noexcept -> const std::string &
Get the conflicting operation identifier.
Definition uritemplate_error.h:123
auto right() const noexcept -> const std::string &
Get the conflicting variable name.
Definition uritemplate_error.h:64
auto operation_id() const noexcept -> const std::string &
Get the offending operation identifier.
Definition uritemplate_error.h:103
URITemplateRouterDuplicateOperationIdError(const std::string_view operation_id)
Construct an error given the conflicting operation identifier.
Definition uritemplate_error.h:118
URITemplateRouterVariableMismatchError(const std::string_view left, const std::string_view right)
Construct an error given the existing and conflicting variable names.
Definition uritemplate_error.h:53
URITemplateRouterReadError(std::filesystem::path path)
Construct an error given the target path.
Definition uritemplate_error.h:156
URITemplateRouterInvalidOperationIdError(const std::string_view operation_id)
Construct an error given the offending operation identifier.
Definition uritemplate_error.h:99
URITemplateRouterInvalidSegmentError(const StaticString message, const std::string_view segment)
Construct an error given a descriptive message and the offending segment.
Definition uritemplate_error.h:79
auto left() const noexcept -> const std::string &
Get the existing variable name.
Definition uritemplate_error.h:59
auto column() const noexcept -> std::uint64_t
Get the column number of the error.
Definition uritemplate_error.h:29
URITemplateParseError(const std::uint64_t column) noexcept
Construct an error given the column number where parsing failed.
Definition uritemplate_error.h:25
URITemplateExpansionError(const StaticString message) noexcept
Construct an error with a descriptive message.
Definition uritemplate_error.h:43
URITemplateRouterSaveError(const StaticString message, std::filesystem::path path)
Construct an error given a descriptive message and the target path.
Definition uritemplate_error.h:137
auto path() const noexcept -> const std::filesystem::path &
Get the path that could not be read.
Definition uritemplate_error.h:161
auto path() const noexcept -> const std::filesystem::path &
Get the path that could not be saved.
Definition uritemplate_error.h:142