Coverage Report

Created: 2026-03-09 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boost/boost/json/impl/error.ipp
Line
Count
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
error_code_category_t::name() const noexcept
36
0
{
37
0
    return "boost.json";
38
0
}
39
40
char const*
41
error_code_category_t::message( int ev, char*, std::size_t ) const noexcept
42
0
{
43
0
    switch(static_cast<error>(ev))
44
0
    {
45
0
    default:
46
0
case error::syntax: return "syntax error";
47
0
case error::extra_data: return "extra data";
48
0
case error::incomplete: return "incomplete JSON";
49
0
case error::exponent_overflow: return "exponent overflow";
50
0
case error::too_deep: return "too deep";
51
0
case error::illegal_leading_surrogate: return "illegal leading surrogate";
52
0
case error::illegal_trailing_surrogate: return "illegal trailing surrogate";
53
0
case error::expected_hex_digit: return "expected hex digit";
54
0
case error::expected_utf16_escape: return "expected utf16 escape";
55
0
case error::object_too_large: return "object too large";
56
0
case error::array_too_large: return "array too large";
57
0
case error::key_too_large: return "key too large";
58
0
case error::string_too_large: return "string too large";
59
0
case error::number_too_large: return "number too large";
60
0
case error::input_error: return "input error";
61
62
0
case error::exception: return "got exception";
63
0
case error::out_of_range: return "out of range";
64
0
case error::test_failure: return "test failure";
65
66
0
case error::missing_slash: return "missing slash character";
67
0
case error::invalid_escape: return "invalid escape sequence";
68
0
case error::token_not_number: return "token is not a number";
69
0
case error::value_is_scalar: return "current value is scalar";
70
0
case error::not_found: return "no referenced value";
71
0
case error::token_overflow: return "token overflow";
72
0
case error::past_the_end: return "past-the-end token not supported";
73
74
0
case error::not_number: return "not a number";
75
0
case error::not_exact: return "not exact";
76
0
case error::not_null: return "value is not null";
77
0
case error::not_bool: return "value is not boolean";
78
0
case error::not_array: return "value is not an array";
79
0
case error::not_object: return "value is not an object";
80
0
case error::not_string: return "value is not a string";
81
0
case error::not_int64: return "value is not a std::int64_t number";
82
0
case error::not_uint64: return "value is not a std::uint64_t number";
83
0
case error::not_double: return "value is not a double";
84
0
case error::not_integer: return "value is not integer";
85
0
case error::size_mismatch: return "source composite size does not match target size";
86
0
case error::exhausted_variants: return "exhausted all variants";
87
0
case error::unknown_name: return "unknown name";
88
0
    }
89
0
}
90
91
std::string
92
error_code_category_t::message( int ev ) const
93
0
{
94
0
    return message( ev, nullptr, 0 );
95
0
}
96
97
system::error_condition
98
error_code_category_t::default_error_condition( int ev) const noexcept
99
0
{
100
0
    switch(static_cast<error>(ev))
101
0
    {
102
0
    default:
103
0
        return {ev, *this};
104
105
0
case error::syntax:
106
0
case error::extra_data:
107
0
case error::incomplete:
108
0
case error::exponent_overflow:
109
0
case error::too_deep:
110
0
case error::illegal_leading_surrogate:
111
0
case error::illegal_trailing_surrogate:
112
0
case error::expected_hex_digit:
113
0
case error::expected_utf16_escape:
114
0
case error::object_too_large:
115
0
case error::array_too_large:
116
0
case error::key_too_large:
117
0
case error::string_too_large:
118
0
case error::number_too_large:
119
0
case error::input_error:
120
0
    return condition::parse_error;
121
122
0
case error::missing_slash:
123
0
case error::invalid_escape:
124
0
    return condition::pointer_parse_error;
125
126
0
case error::token_not_number:
127
0
case error::value_is_scalar:
128
0
case error::not_found:
129
0
case error::token_overflow:
130
0
case error::past_the_end:
131
0
    return condition::pointer_use_error;
132
133
0
case error::not_number:
134
0
case error::not_exact:
135
0
case error::not_null:
136
0
case error::not_bool:
137
0
case error::not_array:
138
0
case error::not_object:
139
0
case error::not_string:
140
0
case error::not_int64:
141
0
case error::not_uint64:
142
0
case error::not_double:
143
0
case error::not_integer:
144
0
case error::size_mismatch:
145
0
case error::exhausted_variants:
146
0
case error::unknown_name:
147
0
    return condition::conversion_error;
148
149
0
case error::exception:
150
0
case error::out_of_range:
151
0
    return condition::generic_error;
152
0
    }
153
0
}
154
155
char const*
156
error_condition_category_t::name() const noexcept
157
0
{
158
0
    return "boost.json";
159
0
}
160
161
char const*
162
error_condition_category_t::message( int cv, char*, std::size_t ) const noexcept
163
0
{
164
0
    switch(static_cast<condition>(cv))
165
0
    {
166
0
    default:
167
0
    case condition::parse_error:
168
0
        return "A JSON parse error occurred";
169
0
    case condition::pointer_parse_error:
170
0
        return "A JSON Pointer parse error occurred";
171
0
    case condition::pointer_use_error:
172
0
        return "An error occurred when JSON Pointer was used with"
173
0
            " a value";
174
0
    case condition::conversion_error:
175
0
        return "An error occurred during conversion";
176
0
    }
177
0
}
178
179
std::string
180
error_condition_category_t::message( int cv ) const
181
0
{
182
0
    return message( cv, nullptr, 0 );
183
0
}
184
185
} // namespace detail
186
187
} // namespace json
188
} // namespace boost
189
190
#endif