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