15 #include <daw/daw_attributes.h>
16 #include <daw/daw_likely.h>
17 #include <daw/daw_not_null.h>
20 #include <daw/stdinc/move_fwd_exch.h>
22 #include <string_view>
24 #if defined( DAW_JSON_SHOW_ERROR_BEFORE_TERMINATE )
29 #if defined( DAW_USE_EXCEPTIONS )
37 #if defined( DAW_USE_EXCEPTIONS )
38 [[noreturn, maybe_unused]] DAW_ATTRIB_NOINLINE
inline void
39 default_error_handler_throwing( json_exception &&jex,
void * ) {
40 throw std::move( jex );
44 [[noreturn, maybe_unused]] DAW_ATTRIB_NOINLINE
inline void
46 #if defined( DAW_JSON_SHOW_ERROR_BEFORE_TERMINATE )
47 std::cerr <<
"Error: " << jex.reason( ) <<
'\n';
55 daw::not_null<void ( * )( json_exception &&,
void * )>;
57 #if defined( DAW_USE_EXCEPTIONS )
59 default_error_handler_throwing;
66 namespace json_details {
67 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
68 handle_error( json_exception &&jex ) {
75 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
77 json_details::handle_error( json_exception( reason ) );
80 template<
typename ParseState>
81 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
83 if( location.first ) {
84 json_details::handle_error( json_exception( reason, location.first ) );
86 if( location.class_first ) {
87 json_details::handle_error(
88 json_exception( reason, location.class_first ) );
90 json_details::handle_error( json_exception( reason ) );
93 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
95 json_details::handle_error( json_exception( reason ) );
98 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
100 json_details::handle_error( json_exception( reason ) );
103 template<
typename ParseState>
104 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
106 ParseState
const &location ) {
107 if( location.class_first and location.first ) {
108 static constexpr std::size_t max_len = 150;
109 std::size_t
const len = [&]( ) -> std::size_t {
110 if( location.first ==
nullptr or location.class_first ==
nullptr ) {
111 if( location.class_first ==
nullptr or
112 location.class_last ==
nullptr ) {
115 auto const dist =
static_cast<std::size_t
>( location.class_last -
116 location.class_first );
117 if( dist < max_len ) {
122 auto const dist =
static_cast<std::size_t
>( location.class_first -
123 location.first + 1 );
124 if( dist < max_len ) {
129 json_details::handle_error( json_exception(
130 reason, std::string_view( location.class_first, len ) ) );
132 json_details::handle_error( json_exception( reason ) );
135 template<
typename ParseState>
136 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
138 ParseState
const &location ) {
139 if( location.first ) {
140 json_details::handle_error( json_exception( reason, location.first ) );
142 if( location.class_first ) {
143 json_details::handle_error(
144 json_exception( reason, location.class_first ) );
146 json_details::handle_error( json_exception( reason ) );
153 #define daw_json_ensure( Bool, ... ) \
155 if( DAW_UNLIKELY( not( Bool ) ) ) { \
156 daw_json_error( __VA_ARGS__ ); \
162 #define daw_json_assert_weak( Bool, ... ) \
164 if constexpr( not ParseState::is_unchecked_input ) { \
165 if( DAW_UNLIKELY( not( Bool ) ) ) { \
166 daw_json_error( __VA_ARGS__ ); \
DAW_ATTRIB_NOINLINE void daw_json_error(ErrorReason reason)
Customization point traits.
daw::not_null< void(*)(json_exception &&, void *)> daw_json_error_handler_t
constexpr bool use_daw_json_exceptions_v
DAW_ATTRIB_NOINLINE void default_error_handler_terminating(json_exception &&jex, void *)
static thread_local daw_json_error_handler_t daw_json_error_handler
static thread_local void * daw_json_error_handler_data
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.