From 4a37ee9be8ceb65d89e65e5aff27a28151d93082 Mon Sep 17 00:00:00 2001 From: Barinade Date: Sun, 11 Sep 2022 23:13:00 -0500 Subject: [PATCH] reduce copy paste for printing json objects for debugging --- src/Etterna/Singletons/DownloadManager.cpp | 38 ++++++++-------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/Etterna/Singletons/DownloadManager.cpp b/src/Etterna/Singletons/DownloadManager.cpp index 6e5d5ad7dd..9c3284b977 100644 --- a/src/Etterna/Singletons/DownloadManager.cpp +++ b/src/Etterna/Singletons/DownloadManager.cpp @@ -267,6 +267,14 @@ EmptyTempDLFileDir() FILEMAN->Remove(file); } } +inline std::string +jsonObjectToString(Value& doc) +{ + StringBuffer buffer; + Writer w(buffer); + doc.Accept(w); + return buffer.GetString(); +} DownloadManager::DownloadManager() { EmptyTempDLFileDir(); @@ -1485,13 +1493,10 @@ DownloadManager::RequestReplayData(const string& scoreid, return; } if (d.HasMember("errors")) { - StringBuffer buffer; - Writer writer(buffer); - d.Accept(writer); Locator::getLogger()->error( "Replay data request failed for {} (Response: {})", scoreid, - buffer.GetString()); + jsonObjectToString(d)); return; } @@ -1625,13 +1630,10 @@ DownloadManager::RequestChartLeaderBoard(const string& chartkey, !score_obj["attributes"]["judgements"].IsObject() || !score_obj["attributes"].HasMember("skillsets") || !score_obj["attributes"]["skillsets"].IsObject()) { - StringBuffer buffer; - Writer writer(buffer); - score_obj.Accept(writer); Locator::getLogger()->warn( "Malformed score in chart leaderboard (chart: {}): {}", chartkey, - buffer.GetString()); + jsonObjectToString(score_obj)); continue; } auto& score = score_obj["attributes"]; @@ -2024,12 +2026,9 @@ DownloadManager::RefreshTop25(Skillset ss) auto& scores = d["data"]; for (auto& score_obj : scores.GetArray()) { if (!score_obj.HasMember("attributes")) { - StringBuffer buffer; - Writer writer(buffer); - score_obj.Accept(writer); Locator::getLogger()->warn( "Malformed single score in top25 scores request response: {}", - buffer.GetString()); + jsonObjectToString(score_obj)); continue; } auto& score = score_obj["attributes"]; @@ -2046,12 +2045,9 @@ DownloadManager::RefreshTop25(Skillset ss) (!score["skillsets"].HasMember(SkillsetToString(ss).c_str()) || !score["skillsets"][SkillsetToString(ss).c_str()] .IsNumber()))) { - StringBuffer buffer; - Writer writer(buffer); - score_obj.Accept(writer); Locator::getLogger()->warn( "Malformed single score in top25 scores request response: {}", - buffer.GetString()); + jsonObjectToString(score_obj)); continue; } OnlineTopScore tmp; @@ -2271,12 +2267,9 @@ DownloadManager::RefreshPackList(const string& url) else if (pack.HasMember("name") && pack["name"].IsString()) tmp.name = pack["name"].GetString(); else { - StringBuffer buffer; - Writer writer(buffer); - pack_obj.Accept(writer); Locator::getLogger()->warn( "Missing pack name in packlist element: {}", - buffer.GetString()); + jsonObjectToString(pack_obj)); continue; } @@ -2291,12 +2284,9 @@ DownloadManager::RefreshPackList(const string& url) else tmp.mirror = ""; if (tmp.url.empty() && tmp.mirror.empty()) { - StringBuffer buffer; - Writer writer(buffer); - pack_obj.Accept(writer); Locator::getLogger()->warn( "Missing download link in packlist element: {}", - buffer.GetString()); + jsonObjectToString(pack_obj)); continue; } if (tmp.url.empty())