diff --git a/include/ircd/json/json.h b/include/ircd/json/json.h index d165cb721..56f145491 100644 --- a/include/ircd/json/json.h +++ b/include/ircd/json/json.h @@ -138,7 +138,10 @@ ircd::json::print(const mutable_buffer &buf, if(unlikely(!valid(sv, std::nothrow))) //note: false alarm when T=json::member throw print_error { - "print (%zu): %s", sv.size(), sv + "print %zu bytes: %s: %s", + sv.size(), + why(sv), + sv }; buf[sv.size()] = '\0'; @@ -161,13 +164,19 @@ ircd::json::strung::strung(T&&... t) if(unlikely(size(sv) != size(out))) throw print_error { - "stringified:%zu != serialized:%zu: %s", size(sv), size(out), sv + "stringified:%zu != serialized:%zu: %s", + size(sv), + size(out), + sv }; if(unlikely(!valid(sv, std::nothrow))) //note: false alarm when T=json::member throw print_error { - "strung (%zu): %s", size(sv), sv + "strung %zu bytes: %s: %s", + size(sv), + why(sv), + sv }; return sv; diff --git a/include/ircd/json/util.h b/include/ircd/json/util.h index 3ae445332..e5986fbb2 100644 --- a/include/ircd/json/util.h +++ b/include/ircd/json/util.h @@ -37,6 +37,7 @@ namespace ircd::json // Validate JSON - checks if valid JSON (not canonical). bool valid(const string_view &, std::nothrow_t) noexcept; void valid(const string_view &); + std::string why(const string_view &); } inline std::ostream & diff --git a/ircd/json.cc b/ircd/json.cc index 0028c9c20..dde2b11c3 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -2175,6 +2175,18 @@ ircd::json::operator==(const value &a, const value &b) // json.h // +std::string +ircd::json::why(const string_view &s) +try +{ + valid(s); + return {}; +} +catch(const expectation_failure &e) +{ + return e.what(); +} + bool ircd::json::valid(const string_view &s, std::nothrow_t)