remove diagnostics_t class

parent e8dba10f
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <valarray> // valarray #include <valarray> // valarray
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp> #include <nlohmann/detail/meta/type_traits.hpp>
...@@ -28,7 +27,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n) ...@@ -28,7 +27,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_null())) if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
{ {
JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), j));
} }
n = nullptr; n = nullptr;
} }
...@@ -59,7 +58,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) ...@@ -59,7 +58,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
} }
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
} }
} }
...@@ -68,7 +67,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) ...@@ -68,7 +67,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
{ {
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), j));
} }
b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>(); b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
} }
...@@ -78,7 +77,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) ...@@ -78,7 +77,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
} }
...@@ -94,7 +93,7 @@ void from_json(const BasicJsonType& j, ConstructibleStringType& s) ...@@ -94,7 +93,7 @@ void from_json(const BasicJsonType& j, ConstructibleStringType& s)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
...@@ -134,7 +133,7 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) ...@@ -134,7 +133,7 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
l.clear(); l.clear();
std::transform(j.rbegin(), j.rend(), std::transform(j.rbegin(), j.rend(),
...@@ -151,7 +150,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l) ...@@ -151,7 +150,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
l.resize(j.size()); l.resize(j.size());
std::transform(j.begin(), j.end(), std::begin(l), std::transform(j.begin(), j.end(), std::begin(l),
...@@ -242,7 +241,7 @@ void()) ...@@ -242,7 +241,7 @@ void())
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
from_json_array_impl(j, arr, priority_tag<3> {}); from_json_array_impl(j, arr, priority_tag<3> {});
...@@ -253,7 +252,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin) ...@@ -253,7 +252,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
{ {
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), j));
} }
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>(); bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
...@@ -265,7 +264,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) ...@@ -265,7 +264,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_object())) if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
{ {
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), j));
} }
ConstructibleObjectType ret; ConstructibleObjectType ret;
...@@ -319,7 +318,7 @@ void from_json(const BasicJsonType& j, ArithmeticType& val) ...@@ -319,7 +318,7 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
} }
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
} }
} }
...@@ -348,14 +347,14 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& ...@@ -348,14 +347,14 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>&
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
m.clear(); m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
...@@ -368,14 +367,14 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE ...@@ -368,14 +367,14 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
m.clear(); m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
......
#pragma once
#include <string>
#include <vector>
#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/detail/string_escape.hpp>
namespace nlohmann
{
namespace detail
{
template<typename BasicJsonType>
class diagnostics_t
{
public:
diagnostics_t() noexcept = default;
diagnostics_t(const BasicJsonType& j) noexcept
: m_j(&j)
{}
std::string diagnostics() const
{
#if JSON_DIAGNOSTICS
if (m_j == nullptr)
{
return "";
}
std::vector<std::string> tokens;
for (const auto* current = m_j; current->m_parent != nullptr; current = current->m_parent)
{
switch (current->m_parent->type())
{
case value_t::array:
{
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
{
if (&current->m_parent->m_value.array->operator[](i) == current)
{
tokens.emplace_back(std::to_string(i));
break;
}
}
break;
}
case value_t::object:
{
for (const auto& element : *current->m_parent->m_value.object)
{
if (&element.second == current)
{
tokens.emplace_back(element.first.c_str());
break;
}
}
break;
}
default: // LCOV_EXCL_LINE
break; // LCOV_EXCL_LINE
}
}
if (tokens.empty())
{
return ""; // LCOV_EXCL_LINE
}
return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
[](const std::string & a, const std::string & b)
{
return a + "/" + detail::escape(b);
}) + ") ";
#else
return "";
#endif
}
private:
const BasicJsonType* m_j = nullptr;
};
} // namespace detail
} // namespace nlohmann
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#include <string> // to_string #include <string> // to_string
#include <nlohmann/detail/diagnostics_t.hpp> #include <nlohmann/detail/value_t.hpp>
#include <nlohmann/detail/string_escape.hpp>
#include <nlohmann/detail/input/position_t.hpp> #include <nlohmann/detail/input/position_t.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
...@@ -66,6 +67,61 @@ class exception : public std::exception ...@@ -66,6 +67,61 @@ class exception : public std::exception
return "[json.exception." + ename + "." + std::to_string(id_) + "] "; return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
} }
template<typename BasicJsonType>
static std::string diagnostics(const BasicJsonType& leaf_element)
{
#if JSON_DIAGNOSTICS
std::vector<std::string> tokens;
for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent)
{
switch (current->m_parent->type())
{
case value_t::array:
{
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
{
if (&current->m_parent->m_value.array->operator[](i) == current)
{
tokens.emplace_back(std::to_string(i));
break;
}
}
break;
}
case value_t::object:
{
for (const auto& element : *current->m_parent->m_value.object)
{
if (&element.second == current)
{
tokens.emplace_back(element.first.c_str());
break;
}
}
break;
}
default: // LCOV_EXCL_LINE
break; // LCOV_EXCL_LINE
}
}
if (tokens.empty())
{
return "";
}
return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
[](const std::string & a, const std::string & b)
{
return a + "/" + detail::escape(b);
}) + ") ";
#else
return "";
#endif
}
private: private:
/// an exception object as storage for error messages /// an exception object as storage for error messages
std::runtime_error m; std::runtime_error m;
...@@ -129,19 +185,19 @@ class parse_error : public exception ...@@ -129,19 +185,19 @@ class parse_error : public exception
@return parse_error object @return parse_error object
*/ */
template<typename BasicJsonType> template<typename BasicJsonType>
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
position_string(pos) + ": " + diagnostics.diagnostics() + what_arg; position_string(pos) + ": " + exception::diagnostics<BasicJsonType>(context) + what_arg;
return parse_error(id_, pos.chars_read_total, w.c_str()); return parse_error(id_, pos.chars_read_total, w.c_str());
} }
template<typename BasicJsonType> template<typename BasicJsonType>
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
": " + diagnostics.diagnostics() + what_arg; ": " + exception::diagnostics<BasicJsonType>(context) + what_arg;
return parse_error(id_, byte_, w.c_str()); return parse_error(id_, byte_, w.c_str());
} }
...@@ -208,9 +264,9 @@ class invalid_iterator : public exception ...@@ -208,9 +264,9 @@ class invalid_iterator : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static invalid_iterator create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("invalid_iterator", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
return invalid_iterator(id_, w.c_str()); return invalid_iterator(id_, w.c_str());
} }
...@@ -263,9 +319,9 @@ class type_error : public exception ...@@ -263,9 +319,9 @@ class type_error : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static type_error create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("type_error", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("type_error", id_) + exception::diagnostics<BasicJsonType>(context) + what_arg;
return type_error(id_, w.c_str()); return type_error(id_, w.c_str());
} }
...@@ -311,9 +367,9 @@ class out_of_range : public exception ...@@ -311,9 +367,9 @@ class out_of_range : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static out_of_range create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("out_of_range", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("out_of_range", id_) + exception::diagnostics<BasicJsonType>(context) + what_arg;
return out_of_range(id_, w.c_str()); return out_of_range(id_, w.c_str());
} }
...@@ -350,9 +406,9 @@ class other_error : public exception ...@@ -350,9 +406,9 @@ class other_error : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static other_error create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("other_error", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("other_error", id_) + exception::diagnostics<BasicJsonType>(context) + what_arg;
return other_error(id_, w.c_str()); return other_error(id_, w.c_str());
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <utility> // move #include <utility> // move
#include <vector> // vector #include <vector> // vector
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
...@@ -155,7 +154,6 @@ class json_sax_dom_parser ...@@ -155,7 +154,6 @@ class json_sax_dom_parser
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
/*! /*!
@param[in, out] r reference to a JSON value that is manipulated while @param[in, out] r reference to a JSON value that is manipulated while
...@@ -221,7 +219,7 @@ class json_sax_dom_parser ...@@ -221,7 +219,7 @@ class json_sax_dom_parser
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -247,7 +245,7 @@ class json_sax_dom_parser ...@@ -247,7 +245,7 @@ class json_sax_dom_parser
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -332,7 +330,6 @@ class json_sax_dom_callback_parser ...@@ -332,7 +330,6 @@ class json_sax_dom_callback_parser
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
using parser_callback_t = typename BasicJsonType::parser_callback_t; using parser_callback_t = typename BasicJsonType::parser_callback_t;
using parse_event_t = typename BasicJsonType::parse_event_t; using parse_event_t = typename BasicJsonType::parse_event_t;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
json_sax_dom_callback_parser(BasicJsonType& r, json_sax_dom_callback_parser(BasicJsonType& r,
const parser_callback_t cb, const parser_callback_t cb,
...@@ -403,7 +400,7 @@ class json_sax_dom_callback_parser ...@@ -403,7 +400,7 @@ class json_sax_dom_callback_parser
// check object limit // check object limit
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -473,7 +470,7 @@ class json_sax_dom_callback_parser ...@@ -473,7 +470,7 @@ class json_sax_dom_callback_parser
// check array limit // check array limit
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <vector> // vector #include <vector> // vector
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/input/input_adapters.hpp> #include <nlohmann/detail/input/input_adapters.hpp>
#include <nlohmann/detail/input/json_sax.hpp> #include <nlohmann/detail/input/json_sax.hpp>
#include <nlohmann/detail/input/lexer.hpp> #include <nlohmann/detail/input/lexer.hpp>
...@@ -58,7 +57,6 @@ class parser ...@@ -58,7 +57,6 @@ class parser
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using lexer_t = lexer<BasicJsonType, InputAdapterType>; using lexer_t = lexer<BasicJsonType, InputAdapterType>;
using token_type = typename lexer_t::token_type; using token_type = typename lexer_t::token_type;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/// a parser reading from an input adapter /// a parser reading from an input adapter
...@@ -97,7 +95,7 @@ class parser ...@@ -97,7 +95,7 @@ class parser
sdp.parse_error(m_lexer.get_position(), sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_of_input, "value"), diagnostics_t())); exception_message(token_type::end_of_input, "value"), BasicJsonType()));
} }
// in case of an error, return discarded value // in case of an error, return discarded value
...@@ -124,8 +122,7 @@ class parser ...@@ -124,8 +122,7 @@ class parser
{ {
sdp.parse_error(m_lexer.get_position(), sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
exception_message(token_type::end_of_input, "value"), diagnostics_t()));
} }
// in case of an error, return discarded value // in case of an error, return discarded value
...@@ -163,8 +160,7 @@ class parser ...@@ -163,8 +160,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
exception_message(token_type::end_of_input, "value"), diagnostics_t()));
} }
return result; return result;
...@@ -210,8 +206,7 @@ class parser ...@@ -210,8 +206,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
exception_message(token_type::value_string, "object key"), diagnostics_t()));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{ {
...@@ -223,8 +218,7 @@ class parser ...@@ -223,8 +218,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
exception_message(token_type::name_separator, "object separator"), diagnostics_t()));
} }
// remember we are now inside an object // remember we are now inside an object
...@@ -267,7 +261,7 @@ class parser ...@@ -267,7 +261,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", diagnostics_t())); out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", BasicJsonType()));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
...@@ -337,16 +331,14 @@ class parser ...@@ -337,16 +331,14 @@ class parser
// using "uninitialized" to avoid "expected" message // using "uninitialized" to avoid "expected" message
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), BasicJsonType()));
exception_message(token_type::uninitialized, "value"), diagnostics_t()));
} }
default: // the last token was unexpected default: // the last token was unexpected
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), BasicJsonType()));
exception_message(token_type::literal_or_value, "value"), diagnostics_t()));
} }
} }
} }
...@@ -392,8 +384,7 @@ class parser ...@@ -392,8 +384,7 @@ class parser
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), BasicJsonType()));
exception_message(token_type::end_array, "array"), diagnostics_t()));
} }
else // object else // object
{ {
...@@ -405,8 +396,7 @@ class parser ...@@ -405,8 +396,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
exception_message(token_type::value_string, "object key"), diagnostics_t()));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
...@@ -419,8 +409,7 @@ class parser ...@@ -419,8 +409,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
exception_message(token_type::name_separator, "object separator"), diagnostics_t()));
} }
// parse values // parse values
...@@ -448,8 +437,7 @@ class parser ...@@ -448,8 +437,7 @@ class parser
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), BasicJsonType()));
exception_message(token_type::end_object, "object"), diagnostics_t()));
} }
} }
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
#include <type_traits> // conditional, is_const, remove_const #include <type_traits> // conditional, is_const, remove_const
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/iterators/internal_iterator.hpp> #include <nlohmann/detail/iterators/internal_iterator.hpp>
#include <nlohmann/detail/iterators/primitive_iterator.hpp> #include <nlohmann/detail/iterators/primitive_iterator.hpp>
...@@ -52,7 +51,6 @@ class iter_impl ...@@ -52,7 +51,6 @@ class iter_impl
// make sure BasicJsonType is basic_json or const basic_json // make sure BasicJsonType is basic_json or const basic_json
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
"iter_impl only accepts (const) basic_json"); "iter_impl only accepts (const) basic_json");
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
...@@ -259,7 +257,7 @@ class iter_impl ...@@ -259,7 +257,7 @@ class iter_impl
} }
case value_t::null: case value_t::null:
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
default: default:
{ {
...@@ -268,7 +266,7 @@ class iter_impl ...@@ -268,7 +266,7 @@ class iter_impl
return *m_object; return *m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
} }
} }
} }
...@@ -302,7 +300,7 @@ class iter_impl ...@@ -302,7 +300,7 @@ class iter_impl
return m_object; return m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
} }
} }
} }
...@@ -403,7 +401,7 @@ class iter_impl ...@@ -403,7 +401,7 @@ class iter_impl
// if objects are not the same, the comparison is undefined // if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
{ {
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
} }
JSON_ASSERT(m_object != nullptr); JSON_ASSERT(m_object != nullptr);
...@@ -440,7 +438,7 @@ class iter_impl ...@@ -440,7 +438,7 @@ class iter_impl
// if objects are not the same, the comparison is undefined // if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
{ {
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
} }
JSON_ASSERT(m_object != nullptr); JSON_ASSERT(m_object != nullptr);
...@@ -448,7 +446,7 @@ class iter_impl ...@@ -448,7 +446,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", *m_object));
case value_t::array: case value_t::array:
return (m_it.array_iterator < other.m_it.array_iterator); return (m_it.array_iterator < other.m_it.array_iterator);
...@@ -496,7 +494,7 @@ class iter_impl ...@@ -496,7 +494,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
case value_t::array: case value_t::array:
{ {
...@@ -567,7 +565,7 @@ class iter_impl ...@@ -567,7 +565,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
case value_t::array: case value_t::array:
return m_it.array_iterator - other.m_it.array_iterator; return m_it.array_iterator - other.m_it.array_iterator;
...@@ -588,13 +586,13 @@ class iter_impl ...@@ -588,13 +586,13 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", *m_object));
case value_t::array: case value_t::array:
return *std::next(m_it.array_iterator, n); return *std::next(m_it.array_iterator, n);
case value_t::null: case value_t::null:
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
default: default:
{ {
...@@ -603,7 +601,7 @@ class iter_impl ...@@ -603,7 +601,7 @@ class iter_impl
return *m_object; return *m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
} }
} }
} }
...@@ -621,7 +619,7 @@ class iter_impl ...@@ -621,7 +619,7 @@ class iter_impl
return m_it.object_iterator->first; return m_it.object_iterator->first;
} }
JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", *m_object));
} }
/*! /*!
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> // move #include <utility> // move
#include <vector> // vector #include <vector> // vector
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/string_escape.hpp> #include <nlohmann/detail/string_escape.hpp>
...@@ -23,8 +22,6 @@ class json_pointer ...@@ -23,8 +22,6 @@ class json_pointer
NLOHMANN_BASIC_JSON_TPL_DECLARATION NLOHMANN_BASIC_JSON_TPL_DECLARATION
friend class basic_json; friend class basic_json;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/*! /*!
@brief create JSON pointer @brief create JSON pointer
...@@ -251,7 +248,7 @@ class json_pointer ...@@ -251,7 +248,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", diagnostics_t())); JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
} }
reference_tokens.pop_back(); reference_tokens.pop_back();
...@@ -275,7 +272,7 @@ class json_pointer ...@@ -275,7 +272,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", diagnostics_t())); JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
} }
return reference_tokens.back(); return reference_tokens.back();
...@@ -341,13 +338,13 @@ class json_pointer ...@@ -341,13 +338,13 @@ class json_pointer
// error condition (cf. RFC 6901, Sect. 4) // error condition (cf. RFC 6901, Sect. 4)
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0')) if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
{ {
JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", diagnostics_t())); JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType()));
} }
// error condition (cf. RFC 6901, Sect. 4) // error condition (cf. RFC 6901, Sect. 4)
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9'))) if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
{ {
JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", diagnostics_t())); JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType()));
} }
std::size_t processed_chars = 0; std::size_t processed_chars = 0;
...@@ -358,20 +355,20 @@ class json_pointer ...@@ -358,20 +355,20 @@ class json_pointer
} }
JSON_CATCH(std::out_of_range&) JSON_CATCH(std::out_of_range&)
{ {
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", diagnostics_t())); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
} }
// check if the string was completely read // check if the string was completely read
if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size())) if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
{ {
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", diagnostics_t())); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
} }
// only triggered on special platforms (like 32bit), see also // only triggered on special platforms (like 32bit), see also
// https://github.com/nlohmann/json/pull/2203 // https://github.com/nlohmann/json/pull/2203
if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
{ {
JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", diagnostics_t())); // LCOV_EXCL_LINE JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType())); // LCOV_EXCL_LINE
} }
return static_cast<size_type>(res); return static_cast<size_type>(res);
...@@ -382,7 +379,7 @@ class json_pointer ...@@ -382,7 +379,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", diagnostics_t())); JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
} }
json_pointer result = *this; json_pointer result = *this;
...@@ -445,7 +442,7 @@ class json_pointer ...@@ -445,7 +442,7 @@ class json_pointer
single value; that is, with an empty list of reference tokens. single value; that is, with an empty list of reference tokens.
*/ */
default: default:
JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", diagnostics_t(j))); JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j));
} }
} }
...@@ -517,7 +514,7 @@ class json_pointer ...@@ -517,7 +514,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -550,7 +547,7 @@ class json_pointer ...@@ -550,7 +547,7 @@ class json_pointer
// "-" always fails the range check // "-" always fails the range check
JSON_THROW(detail::out_of_range::create(402, JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) + "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", diagnostics_t(*ptr))); ") is out of range", *ptr));
} }
// note: at performs range check // note: at performs range check
...@@ -559,7 +556,7 @@ class json_pointer ...@@ -559,7 +556,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -597,7 +594,7 @@ class json_pointer ...@@ -597,7 +594,7 @@ class json_pointer
if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
{ {
// "-" cannot be used for const access // "-" cannot be used for const access
JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", *ptr));
} }
// use unchecked array access // use unchecked array access
...@@ -606,7 +603,7 @@ class json_pointer ...@@ -606,7 +603,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -639,7 +636,7 @@ class json_pointer ...@@ -639,7 +636,7 @@ class json_pointer
// "-" always fails the range check // "-" always fails the range check
JSON_THROW(detail::out_of_range::create(402, JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) + "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", diagnostics_t(*ptr))); ") is out of range", *ptr));
} }
// note: at performs range check // note: at performs range check
...@@ -648,7 +645,7 @@ class json_pointer ...@@ -648,7 +645,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -752,7 +749,7 @@ class json_pointer ...@@ -752,7 +749,7 @@ class json_pointer
// check if nonempty reference string begins with slash // check if nonempty reference string begins with slash
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
{ {
JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", diagnostics_t())); JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType()));
} }
// extract the reference tokens: // extract the reference tokens:
...@@ -787,7 +784,7 @@ class json_pointer ...@@ -787,7 +784,7 @@ class json_pointer
(reference_token[pos + 1] != '0' && (reference_token[pos + 1] != '0' &&
reference_token[pos + 1] != '1'))) reference_token[pos + 1] != '1')))
{ {
JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", diagnostics_t())); JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType()));
} }
} }
...@@ -874,7 +871,7 @@ class json_pointer ...@@ -874,7 +871,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(!value.is_object())) if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
{ {
JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", diagnostics_t(value))); JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", value));
} }
BasicJsonType result; BasicJsonType result;
...@@ -884,7 +881,7 @@ class json_pointer ...@@ -884,7 +881,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive())) if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
{ {
JSON_THROW(detail::type_error::create(315, "values in object must be primitive", diagnostics_t(element.second))); JSON_THROW(detail::type_error::create(315, "values in object must be primitive", element.second));
} }
// assign value to reference pointed to by JSON pointer; Note that if // assign value to reference pointed to by JSON pointer; Note that if
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <string> // string #include <string> // string
#include <cmath> // isnan, isinf #include <cmath> // isnan, isinf
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/input/binary_reader.hpp> #include <nlohmann/detail/input/binary_reader.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/output/output_adapters.hpp> #include <nlohmann/detail/output/output_adapters.hpp>
...@@ -30,7 +29,6 @@ class binary_writer ...@@ -30,7 +29,6 @@ class binary_writer
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/*! /*!
...@@ -59,7 +57,7 @@ class binary_writer ...@@ -59,7 +57,7 @@ class binary_writer
default: default:
{ {
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), diagnostics_t(j)));; JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
} }
} }
} }
...@@ -908,7 +906,7 @@ class binary_writer ...@@ -908,7 +906,7 @@ class binary_writer
const auto it = name.find(static_cast<typename string_t::value_type>(0)); const auto it = name.find(static_cast<typename string_t::value_type>(0));
if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
{ {
JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", diagnostics_t(j))); JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", j));
} }
return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
...@@ -1032,7 +1030,7 @@ class binary_writer ...@@ -1032,7 +1030,7 @@ class binary_writer
} }
else else
{ {
JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", diagnostics_t(j))); JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", j));
} }
} }
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <utility> // move #include <utility> // move
#include <nlohmann/detail/conversions/to_chars.hpp> #include <nlohmann/detail/conversions/to_chars.hpp>
#include <nlohmann/detail/diagnostics_t.hpp>
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp> #include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp> #include <nlohmann/detail/meta/cpp_future.hpp>
...@@ -45,7 +44,6 @@ class serializer ...@@ -45,7 +44,6 @@ class serializer
using number_integer_t = typename BasicJsonType::number_integer_t; using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using binary_char_t = typename BasicJsonType::binary_t::value_type; using binary_char_t = typename BasicJsonType::binary_t::value_type;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
static constexpr std::uint8_t UTF8_ACCEPT = 0; static constexpr std::uint8_t UTF8_ACCEPT = 0;
static constexpr std::uint8_t UTF8_REJECT = 1; static constexpr std::uint8_t UTF8_REJECT = 1;
...@@ -501,7 +499,7 @@ class serializer ...@@ -501,7 +499,7 @@ class serializer
{ {
std::string sn(3, '\0'); std::string sn(3, '\0');
(std::snprintf)(&sn[0], sn.size(), "%.2X", byte); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, diagnostics_t())); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType()));
} }
case error_handler_t::ignore: case error_handler_t::ignore:
...@@ -595,7 +593,7 @@ class serializer ...@@ -595,7 +593,7 @@ class serializer
{ {
std::string sn(3, '\0'); std::string sn(3, '\0');
(std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back())); (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, diagnostics_t())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
} }
case error_handler_t::ignore: case error_handler_t::ignore:
......
This diff is collapsed.
...@@ -496,8 +496,11 @@ TEST_CASE("JSON pointers") ...@@ -496,8 +496,11 @@ TEST_CASE("JSON pointers")
// error for nonprimitve values // error for nonprimitve values
CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), json::type_error&); CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), json::type_error&);
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), #if JSON_DIAGNOSTICS
"[json.exception.type_error.315] values in object must be primitive"); CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] (/~11) values in object must be primitive");
#else
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] values in object must be primitive");
#endif
// error for conflicting values // error for conflicting values
json j_error = {{"", 42}, {"/foo", 17}}; json j_error = {{"", 42}, {"/foo", 17}};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment