LCOV - code coverage report
Current view: top level - json/impl - error.ipp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 74 74
Test Date: 2025-12-23 17:20:51 Functions: 100.0 % 7 7

            Line data    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          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          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          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           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           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           76 :     return message( cv, nullptr, 0 );
     183              : }
     184              : 
     185              : } // namespace detail
     186              : 
     187              : } // namespace json
     188              : } // namespace boost
     189              : 
     190              : #endif
        

Generated by: LCOV version 2.1