1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/json
8 //
9 
10 #ifndef BOOST_JSON_ERROR_HPP
11 #define BOOST_JSON_ERROR_HPP
12 
13 #include <boost/json/detail/config.hpp>
14 #ifndef BOOST_JSON_STANDALONE
15 # include <boost/system/error_code.hpp>
16 # include <boost/system/system_error.hpp>
17 #else
18 # include <system_error>
19 #endif
20 
21 BOOST_JSON_NS_BEGIN
22 
23 #ifdef BOOST_JSON_DOCS
24 
25 /** The type of error code used by the library.
26 
27     This type alias is set depending
28     on how the library is configured:
29 
30     @par Use with Boost
31 
32     If the macro `BOOST_JSON_STANDALONE` is
33     not defined, this type will be an alias
34     for `boost::system::error_code`.
35     Compiling a program using the library will
36     require Boost, and a compiler conforming
37     to C++11 or later.
38 
39     @par Use without Boost
40 
41     If the macro `BOOST_JSON_STANDALONE` is
42     defined, this type will be an alias
43     for `std::error_code`.
44     Compiling a program using the library will
45     require only a compiler conforming to C++17
46     or later.
47 
48     @see https://en.cppreference.com/w/cpp/error/error_code
49 */
50 using error_code = __see_below__;
51 
52 /** The type of error category used by the library.
53 
54     This type alias is set depending
55     on how the library is configured:
56 
57     @par Use with Boost
58 
59     If the macro `BOOST_JSON_STANDALONE` is
60     not defined, this type will be an alias
61     for `boost::system::error_category`.
62     Compiling a program using the library will
63     require Boost, and a compiler conforming
64     to C++11 or later.
65 
66     @par Use without Boost
67 
68     If the macro `BOOST_JSON_STANDALONE` is
69     defined, this type will be an alias
70     for `std::error_category`.
71     Compiling a program using the library will
72     require only a compiler conforming to C++17
73     or later.
74 
75     @see https://en.cppreference.com/w/cpp/error/error_category
76 */
77 using error_category = __see_below__;
78 
79 /** The type of error condition used by the library.
80 
81     This type alias is set depending
82     on how the library is configured:
83 
84     @par Use with Boost
85 
86     If the macro `BOOST_JSON_STANDALONE` is
87     not defined, this type will be an alias
88     for `boost::system::error_condition`.
89     Compiling a program using the library will
90     require Boost, and a compiler conforming
91     to C++11 or later.
92 
93     @par Use without Boost
94 
95     If the macro `BOOST_JSON_STANDALONE` is
96     defined, this type will be an alias
97     for `std::error_condition`.
98     Compiling a program using the library will
99     require only a compiler conforming to C++17
100     or later.
101 
102     @see https://en.cppreference.com/w/cpp/error/error_condition
103 */
104 using error_condition = __see_below__;
105 
106 /** The type of system error thrown by the library.
107 
108     This type alias is set depending
109     on how the library is configured:
110 
111     @par Use with Boost
112 
113     If the macro `BOOST_JSON_STANDALONE` is
114     not defined, this type will be an alias
115     for `boost::system::system_error`.
116     Compiling a program using the library will
117     require Boost, and a compiler conforming
118     to C++11 or later.
119 
120     @par Use without Boost
121 
122     If the macro `BOOST_JSON_STANDALONE` is
123     defined, this type will be an alias
124     for `std::system_error`.
125     Compiling a program using the library will
126     require only a compiler conforming to C++17
127     or later.
128 
129     @see https://en.cppreference.com/w/cpp/error/system_error
130 */
131 using system_error = __see_below__;
132 
133 /// Returns the generic error category used by the library.
134 error_category const&
135 generic_category();
136 
137 #elif ! defined(BOOST_JSON_STANDALONE)
138 
139 using error_code = boost::system::error_code;
140 using error_category = boost::system::error_category;
141 using error_condition = boost::system::error_condition;
142 using system_error = boost::system::system_error;
143 using boost::system::generic_category;
144 
145 #else
146 
147 using error_code = std::error_code;
148 using error_category = std::error_category;
149 using error_condition = std::error_condition;
150 using system_error = std::system_error;
151 using std::generic_category;
152 
153 #endif
154 
155 /** Error codes returned by JSON operations
156 
157 */
158 enum class error
159 {
160     //
161     // parse errors
162     //
163 
164     /// syntax error
165     syntax = 1,
166 
167     /// extra data
168     extra_data,
169 
170     /// incomplete JSON
171     incomplete,
172 
173     /// exponent too large
174     exponent_overflow,
175 
176     /// too deep
177     too_deep,
178 
179     /// illegal leading surrogate
180     illegal_leading_surrogate,
181 
182     /// illegal trailing surrogate
183     illegal_trailing_surrogate,
184 
185     /// expected hex digit
186     expected_hex_digit,
187 
188     /// expected utf16 escape
189     expected_utf16_escape,
190 
191     /// An object contains too many elements
192     object_too_large,
193 
194     /// An array contains too many elements
195     array_too_large,
196 
197     /// A key is too large
198     key_too_large,
199 
200     /// A string is too large
201     string_too_large,
202 
203     /// The parser encountered an exception and must be reset
204     exception,
205 
206     //----------------------------------
207 
208     /// not a number
209     not_number,
210 
211     /// number cast is not exact
212     not_exact,
213 
214     /// test failure
215     test_failure,
216 };
217 
218 /** Error conditions corresponding to JSON errors
219 */
220 enum class condition
221 {
222     /// A parser-related error
223     parse_error = 1,
224 
225     /// An error on assignment to or from a JSON value
226     assign_error
227 };
228 
229 BOOST_JSON_NS_END
230 
231 #include <boost/json/impl/error.hpp>
232 
233 #endif
234