GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: impl/error.ipp
Date: 2025-12-23 17:20:53
Exec Total Coverage
Lines: 74 74 100.0%
Functions: 7 7 100.0%
Branches: 51 51 100.0%

Line Branch Exec Source
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 465 error_code_category_t::name() const noexcept
36 {
37 465 return "boost.json";
38 }
39
40 char const*
41 465 error_code_category_t::message( int ev, char*, std::size_t ) const noexcept
42 {
43
39/39
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 10 times.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 7 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 25 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 4 times.
✓ Branch 19 taken 3 times.
✓ Branch 20 taken 5 times.
✓ Branch 21 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 47 times.
✓ Branch 26 taken 63 times.
✓ Branch 27 taken 20 times.
✓ Branch 28 taken 22 times.
✓ Branch 29 taken 40 times.
✓ Branch 30 taken 34 times.
✓ Branch 31 taken 47 times.
✓ Branch 32 taken 15 times.
✓ Branch 33 taken 15 times.
✓ Branch 34 taken 15 times.
✓ Branch 35 taken 3 times.
✓ Branch 36 taken 25 times.
✓ Branch 37 taken 1 times.
✓ Branch 38 taken 1 times.
465 switch(static_cast<error>(ev))
44 {
45 12 default:
46 12 case error::syntax: return "syntax error";
47 7 case error::extra_data: return "extra data";
48 17 case error::incomplete: return "incomplete JSON";
49 1 case error::exponent_overflow: return "exponent overflow";
50 1 case error::too_deep: return "too deep";
51 1 case error::illegal_leading_surrogate: return "illegal leading surrogate";
52 1 case error::illegal_trailing_surrogate: return "illegal trailing surrogate";
53 1 case error::expected_hex_digit: return "expected hex digit";
54 1 case error::expected_utf16_escape: return "expected utf16 escape";
55 10 case error::object_too_large: return "object too large";
56 5 case error::array_too_large: return "array too large";
57 2 case error::key_too_large: return "key too large";
58 7 case error::string_too_large: return "string too large";
59 2 case error::number_too_large: return "number too large";
60 2 case error::input_error: return "input error";
61
62 1 case error::exception: return "got exception";
63 25 case error::out_of_range: return "out of range";
64 1 case error::test_failure: return "test failure";
65
66 4 case error::missing_slash: return "missing slash character";
67 3 case error::invalid_escape: return "invalid escape sequence";
68 5 case error::token_not_number: return "token is not a number";
69 3 case error::value_is_scalar: return "current value is scalar";
70 3 case error::not_found: return "no referenced value";
71 1 case error::token_overflow: return "token overflow";
72 1 case error::past_the_end: return "past-the-end token not supported";
73
74 47 case error::not_number: return "not a number";
75 63 case error::not_exact: return "not exact";
76 20 case error::not_null: return "value is not null";
77 22 case error::not_bool: return "value is not boolean";
78 40 case error::not_array: return "value is not an array";
79 34 case error::not_object: return "value is not an object";
80 47 case error::not_string: return "value is not a string";
81 15 case error::not_int64: return "value is not a std::int64_t number";
82 15 case error::not_uint64: return "value is not a std::uint64_t number";
83 15 case error::not_double: return "value is not a double";
84 3 case error::not_integer: return "value is not integer";
85 25 case error::size_mismatch: return "source composite size does not match target size";
86 1 case error::exhausted_variants: return "exhausted all variants";
87 1 case error::unknown_name: return "unknown name";
88 }
89 }
90
91 std::string
92 465 error_code_category_t::message( int ev ) const
93 {
94
1/1
✓ Branch 2 taken 465 times.
930 return message( ev, nullptr, 0 );
95 }
96
97 system::error_condition
98 40 error_code_category_t::default_error_condition( int ev) const noexcept
99 {
100
6/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 2 times.
40 switch(static_cast<error>(ev))
101 {
102 1 default:
103 1 return {ev, *this};
104
105 16 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 16 return condition::parse_error;
121
122 2 case error::missing_slash:
123 case error::invalid_escape:
124 2 return condition::pointer_parse_error;
125
126 5 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 5 return condition::pointer_use_error;
132
133 14 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 14 return condition::conversion_error;
148
149 2 case error::exception:
150 case error::out_of_range:
151 2 return condition::generic_error;
152 }
153 }
154
155 char const*
156 38 error_condition_category_t::name() const noexcept
157 {
158 38 return "boost.json";
159 }
160
161 char const*
162 38 error_condition_category_t::message( int cv, char*, std::size_t ) const noexcept
163 {
164
4/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 14 times.
38 switch(static_cast<condition>(cv))
165 {
166 17 default:
167 case condition::parse_error:
168 17 return "A JSON parse error occurred";
169 2 case condition::pointer_parse_error:
170 2 return "A JSON Pointer parse error occurred";
171 5 case condition::pointer_use_error:
172 return "An error occurred when JSON Pointer was used with"
173 5 " a value";
174 14 case condition::conversion_error:
175 14 return "An error occurred during conversion";
176 }
177 }
178
179 std::string
180 38 error_condition_category_t::message( int cv ) const
181 {
182
1/1
✓ Branch 2 taken 38 times.
76 return message( cv, nullptr, 0 );
183 }
184
185 } // namespace detail
186
187 } // namespace json
188 } // namespace boost
189
190 #endif
191