AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
mappingError.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2020 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-json-export.hpp"
23
24#include <istream>
25#include <exception>
26#include <optional>
27#include <string>
28#include <string_view>
29#include <cstddef>
30
31#include "json/readerContext.hpp"
32
33
34namespace anch::json {
35
43 enum class ErrorCode {
45 INVALID_FORMAT = 0,
46
49
52
58
63 CONSTRAINT_VIOLATION,
64
70
72 UNKNOWN = 9999
73 };
74
84 class ANCH_JSON_EXPORT MappingError: public std::exception {
85
86 // Attributes +
87 private:
89 ErrorCode _code;
90
92 std::string _msg;
93
95 std::string _detail;
96
98 std::string _path;
99 // Attributes -
100
101 // Constructors +
102 public:
110
119 MappingError(ErrorCode code, const anch::json::ReaderContext& context, std::string_view message);
120
129 MappingError(ErrorCode code, std::string_view message);
130 // Constructors -
131
132 // Destructor +
133 public:
137 virtual ~MappingError();
138 // Destructor -
139
140 // Methods +
141 public:
147 virtual const char* what() const noexcept override;
148
157 void prependField(std::string_view field);
158
167 void prependIndex(std::size_t index);
168
169 private:
173 void computeMessage();
174 // Methods -
175
176 // Accessors +
177 public:
184
196 const std::string& getPath() const;
197 // Accessors -
198
199 };
200
201} // anch::json
202
203#include "json/impl/mappingError.hpp"
MappingError(ErrorCode code, const anch::json::ReaderContext &context, std::string_view message)
virtual const char * what() const noexcept override
const std::string & getPath() const
anch::json::ErrorCode getErrorCode() const
void prependIndex(std::size_t index)
MappingError(ErrorCode code, std::string_view message)
void prependField(std::string_view field)
MappingError(ErrorCode code, const anch::json::ReaderContext &context)
JSON reader context.
Definition readerContext.hpp:44
JSON namespace.
Definition constants.hpp:27
ErrorCode
Definition mappingError.hpp:43
@ POTENTIAL_OVERFLOW
Definition mappingError.hpp:51
@ UNKNOWN
Definition mappingError.hpp:72
@ PAYLOAD_TOO_LARGE
Definition mappingError.hpp:69
@ MISSING_FIELD
Definition mappingError.hpp:57
@ UNEXPECTED_FIELD
Definition mappingError.hpp:48
AnCH framework base namespace.
Definition app.hpp:30