Call rapidjson::ParseResult::IsError to check for JSON parsing errors (flutter/engine#29270)

This commit is contained in:
Jason Simmons 2021-10-20 16:53:01 -07:00 committed by GitHub
parent d3504ac447
commit 6e16f8ecd2
2 changed files with 2 additions and 4 deletions

View File

@ -253,7 +253,7 @@ std::vector<PersistentCache::SkSLCache> PersistentCache::LoadSkSLs() const {
rapidjson::ParseResult parse_result =
json_doc.Parse(reinterpret_cast<const char*>(mapping->GetMapping()),
mapping->GetSize());
if (parse_result != rapidjson::ParseErrorCode::kParseErrorNone) {
if (parse_result.IsError()) {
FML_LOG(ERROR) << "Failed to parse json file: " << kAssetFileName;
} else {
for (auto& item : json_doc["data"].GetObject()) {

View File

@ -37,9 +37,7 @@ std::unique_ptr<rapidjson::Document> JsonMessageCodec::DecodeMessageInternal(
auto json_message = std::make_unique<rapidjson::Document>();
rapidjson::ParseResult result =
json_message->Parse(raw_message, message_size);
bool parsing_successful =
result == rapidjson::ParseErrorCode::kParseErrorNone;
if (!parsing_successful) {
if (result.IsError()) {
std::cerr << "Unable to parse JSON message:" << std::endl
<< rapidjson::GetParseError_En(result.Code()) << std::endl;
return nullptr;