Human readable json parse error - original patch was suggested by vegayours@
#include "rapidjson_helpers.h"
#include <contrib/libs/rapidjson/include/rapidjson/document.h>
+#include <contrib/libs/rapidjson/include/rapidjson/error/en.h>
+#include <contrib/libs/rapidjson/include/rapidjson/error/error.h>
#include <contrib/libs/rapidjson/include/rapidjson/reader.h>
#include <contrib/libs/rapidjson/include/rapidjson/stringbuffer.h>
#include <contrib/libs/rapidjson/include/rapidjson/writer.h>
#include <util/generic/stack.h>
#include <util/string/cast.h>
#include <util/system/yassert.h>
+#include <util/string/builder.h>
namespace NJson {
+ namespace {
+ TString PrintError(const rapidjson::ParseResult& result) {
+ return TStringBuilder() << AsStringBuf("Offset: ") << result.Offset()
+ << AsStringBuf(", Code: ") << (int)result.Code()
+ << AsStringBuf(", Error: ") << GetParseError_En(result.Code());
+ }
+ }
+
static const size_t DEFAULT_BUFFER_LEN = 65536;
bool TParserCallbacks::OpenComplexValue(EJsonValueType type) {
@@ -319,7 +330,7 @@ namespace NJson {
if (result.IsError()) {
if (throwOnError) {
- throw TJsonException() << "Offset: " << result.Offset() << ", Code: " << static_cast<int>(result.Code());
+ ythrow TJsonException() << PrintError(result);
} else {
return false;
}
@@ -488,7 +499,7 @@ namespace NJson {
auto result = Read(*config, reader, is, wrapper);
if (result.IsError()) {
- cbs->OnError(result.Offset(), "Code: " + ToString(static_cast<int>(result.Code())));
+ cbs->OnError(result.Offset(), PrintError(result));
return false;
}
