impl/error.ipp

100.0% Lines (74/74) 100.0% Functions (7/7)
Line TLA Hits Source Code
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_IMPL_ERROR_IPP
11 #define BOOST_JSON_IMPL_ERROR_IPP
12
13 #include <boost/json/error.hpp>
14
15 namespace boost {
16 namespace json {
17 namespace detail {
18
19 // msvc 14.0 has a bug that warns about inability to use constexpr
20 // construction here, even though there's no constexpr construction
21 #if defined(_MSC_VER) && _MSC_VER <= 1900
22 # pragma warning( push )
23 # pragma warning( disable : 4592 )
24 #endif
25 BOOST_JSON_CONSTINIT
26 error_code_category_t error_code_category;
27
28 BOOST_JSON_CONSTINIT
29 error_condition_category_t error_condition_category;
30 #if defined(_MSC_VER) && _MSC_VER <= 1900
31 # pragma warning( pop )
32 #endif
33
34 char const*
35 465x error_code_category_t::name() const noexcept
36 {
37 465x return "boost.json";
38 }
39
40 char const*
41 465x error_code_category_t::message( int ev, char*, std::size_t ) const noexcept
42 {
43 465x switch(static_cast<error>(ev))
44 {
45 12x default:
46 12x case error::syntax: return "syntax error";
47 7x case error::extra_data: return "extra data";
48 17x case error::incomplete: return "incomplete JSON";
49 1x case error::exponent_overflow: return "exponent overflow";
50 1x case error::too_deep: return "too deep";
51 1x case error::illegal_leading_surrogate: return "illegal leading surrogate";
52 1x case error::illegal_trailing_surrogate: return "illegal trailing surrogate";
53 1x case error::expected_hex_digit: return "expected hex digit";
54 1x case error::expected_utf16_escape: return "expected utf16 escape";
55 10x case error::object_too_large: return "object too large";
56 5x case error::array_too_large: return "array too large";
57 2x case error::key_too_large: return "key too large";
58 7x case error::string_too_large: return "string too large";
59 2x case error::number_too_large: return "number too large";
60 2x case error::input_error: return "input error";
61
62 1x case error::exception: return "got exception";
63 25x case error::out_of_range: return "out of range";
64 1x case error::test_failure: return "test failure";
65
66 4x case error::missing_slash: return "missing slash character";
67 3x case error::invalid_escape: return "invalid escape sequence";
68 5x case error::token_not_number: return "token is not a number";
69 3x case error::value_is_scalar: return "current value is scalar";
70 3x case error::not_found: return "no referenced value";
71 1x case error::token_overflow: return "token overflow";
72 1x case error::past_the_end: return "past-the-end token not supported";
73
74 47x case error::not_number: return "not a number";
75 63x case error::not_exact: return "not exact";
76 20x case error::not_null: return "value is not null";
77 22x case error::not_bool: return "value is not boolean";
78 40x case error::not_array: return "value is not an array";
79 34x case error::not_object: return "value is not an object";
80 47x case error::not_string: return "value is not a string";
81 15x case error::not_int64: return "value is not a std::int64_t number";
82 15x case error::not_uint64: return "value is not a std::uint64_t number";
83 15x case error::not_double: return "value is not a double";
84 3x case error::not_integer: return "value is not integer";
85 25x case error::size_mismatch: return "source composite size does not match target size";
86 1x case error::exhausted_variants: return "exhausted all variants";
87 1x case error::unknown_name: return "unknown name";
88 }
89 }
90
91 std::string
92 465x error_code_category_t::message( int ev ) const
93 {
94 930x return message( ev, nullptr, 0 );
95 }
96
97 system::error_condition
98 40x error_code_category_t::default_error_condition( int ev) const noexcept
99 {
100 40x switch(static_cast<error>(ev))
101 {
102 1x default:
103 1x return {ev, *this};
104
105 16x case error::syntax:
106 case error::extra_data:
107 case error::incomplete:
108 case error::exponent_overflow:
109 case error::too_deep:
110 case error::illegal_leading_surrogate:
111 case error::illegal_trailing_surrogate:
112 case error::expected_hex_digit:
113 case error::expected_utf16_escape:
114 case error::object_too_large:
115 case error::array_too_large:
116 case error::key_too_large:
117 case error::string_too_large:
118 case error::number_too_large:
119 case error::input_error:
120 16x return condition::parse_error;
121
122 2x case error::missing_slash:
123 case error::invalid_escape:
124 2x return condition::pointer_parse_error;
125
126 5x case error::token_not_number:
127 case error::value_is_scalar:
128 case error::not_found:
129 case error::token_overflow:
130 case error::past_the_end:
131 5x return condition::pointer_use_error;
132
133 14x case error::not_number:
134 case error::not_exact:
135 case error::not_null:
136 case error::not_bool:
137 case error::not_array:
138 case error::not_object:
139 case error::not_string:
140 case error::not_int64:
141 case error::not_uint64:
142 case error::not_double:
143 case error::not_integer:
144 case error::size_mismatch:
145 case error::exhausted_variants:
146 case error::unknown_name:
147 14x return condition::conversion_error;
148
149 2x case error::exception:
150 case error::out_of_range:
151 2x return condition::generic_error;
152 }
153 }
154
155 char const*
156 38x error_condition_category_t::name() const noexcept
157 {
158 38x return "boost.json";
159 }
160
161 char const*
162 38x error_condition_category_t::message( int cv, char*, std::size_t ) const noexcept
163 {
164 38x switch(static_cast<condition>(cv))
165 {
166 17x default:
167 case condition::parse_error:
168 17x return "A JSON parse error occurred";
169 2x case condition::pointer_parse_error:
170 2x return "A JSON Pointer parse error occurred";
171 5x case condition::pointer_use_error:
172 return "An error occurred when JSON Pointer was used with"
173 5x " a value";
174 14x case condition::conversion_error:
175 14x return "An error occurred during conversion";
176 }
177 }
178
179 std::string
180 38x error_condition_category_t::message( int cv ) const
181 {
182 76x return message( cv, nullptr, 0 );
183 }
184
185 } // namespace detail
186
187 } // namespace json
188 } // namespace boost
189
190 #endif
191