Add logging offset for Json parsing errors

This commit is contained in:
Wojtek Figat
2020-12-30 23:50:07 +01:00
parent 29a8abd996
commit 3973452ec3
7 changed files with 20 additions and 18 deletions

View File

@@ -1016,7 +1016,7 @@ public:
document.Parse(json.Get(), json.Length());
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError());
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
DebugLog::ThrowException("Failed to parse Json.");
}

View File

@@ -118,16 +118,16 @@ void BinaryAsset::GetImportMetadata(String& path, String& username) const
}
// Parse metadata and try to get import info
rapidjson_flax::Document doc;
doc.Parse((const char*)Metadata.Get(), Metadata.Length());
if (doc.HasParseError() == false)
rapidjson_flax::Document document;
document.Parse((const char*)Metadata.Get(), Metadata.Length());
if (document.HasParseError() == false)
{
path = JsonTools::GetString(doc, "ImportPath");
username = JsonTools::GetString(doc, "ImportUsername");
path = JsonTools::GetString(document, "ImportPath");
username = JsonTools::GetString(document, "ImportUsername");
}
else
{
Log::JsonParseException(doc.GetParseError(), GetPath());
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), GetPath());
}
}

View File

@@ -128,7 +128,7 @@ Asset::LoadResult JsonAssetBase::loadAsset()
Document.Parse(data.Get<char>(), data.Length());
if (Document.HasParseError())
{
Log::JsonParseException(Document.GetParseError());
Log::JsonParseException(Document.GetParseError(), Document.GetErrorOffset());
return LoadResult::CannotLoadData;
}

View File

@@ -35,7 +35,7 @@ bool JsonStorageProxy::GetAssetInfo(const StringView& path, Guid& resultId, Stri
document.Parse((const char*)fileData.Get(), fileData.Count());
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError(), String(path));
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), String(path));
return false;
}
@@ -104,7 +104,7 @@ bool JsonStorageProxy::ChangeId(const StringView& path, const Guid& newId)
document.Parse((const char*)fileData.Get(), fileData.Count());
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError(), String(path));
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), String(path));
return false;
}

View File

@@ -23,8 +23,9 @@ namespace Log
/// Init
/// </summary>
/// <param name="error">Parsing error code.</param>
JsonParseException(ErrorCode error)
: JsonParseException(error, String::Empty)
/// <param name="offset">Parsing error location.</param>
JsonParseException(ErrorCode error, size_t offset)
: JsonParseException(error, offset, String::Empty)
{
}
@@ -32,9 +33,10 @@ namespace Log
/// Creates default exception with additional data
/// </summary>
/// <param name="error">Parsing error code.</param>
/// <param name="offset">Parsing error location.</param>
/// <param name="additionalInfo">Additional information that help describe error</param>
JsonParseException(ErrorCode error, const String& additionalInfo)
: Exception(String::Format(TEXT("Parsing Json failed with error code {0}. {1}"), static_cast<int32>(error), GetParseError_En(error)), additionalInfo)
JsonParseException(ErrorCode error, size_t offset, const String& additionalInfo)
: Exception(String::Format(TEXT("Parsing Json failed with error code {0} (offset {2}). {1}"), static_cast<int32>(error), GetParseError_En(error), offset), additionalInfo)
{
}
};

View File

@@ -1547,7 +1547,7 @@ bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeM
document.Parse(buffer, bufferSize);
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError());
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
return true;
}
@@ -1587,7 +1587,7 @@ bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeM
document.Parse(buffer, bufferSize);
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError());
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
return true;
}
@@ -1699,7 +1699,7 @@ void Actor::FromJson(const StringAnsiView& json)
document.Parse(json.Get(), json.Length());
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError());
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
return;
}

View File

@@ -786,7 +786,7 @@ bool Level::loadScene(const BytesContainer& sceneData, bool autoInitialize, Scen
document.Parse(sceneData.Get<char>(), sceneData.Length());
if (document.HasParseError())
{
Log::JsonParseException(document.GetParseError());
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
return true;
}