diff --git a/ugc/storage.cpp b/ugc/storage.cpp index 9b99cbefaa..e00ee9a9f1 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -22,6 +22,7 @@ #include #include +#include "3party/Alohalytics/src/alohalytics.h" #include "3party/jansson/myjansson.hpp" #include @@ -212,7 +213,13 @@ void Storage::Load() return; } - CHECK(!data.empty(), ()); + if (data.empty()) + { + ASSERT(false, ()); + alohalytics::Stats::Instance().LogEvent("UGC_File_error", {{"error", "empty index file"}}); + return; + } + DeserializeIndexes(data, m_indexes); if (m_indexes.empty()) return; @@ -398,6 +405,7 @@ size_t Storage::GetNumberOfUnsynchronized() const if (!i.m_deleted && !i.m_synchronized) ++numberOfUnsynchronized; } + return numberOfUnsynchronized; } diff --git a/ugc/ugc_tests/storage_tests.cpp b/ugc/ugc_tests/storage_tests.cpp index 69029f7175..313b3bdc78 100644 --- a/ugc/ugc_tests/storage_tests.cpp +++ b/ugc/ugc_tests/storage_tests.cpp @@ -478,3 +478,14 @@ UNIT_TEST(UGC_IndexMigrationFromV0ToV1Smoke) my::DeleteFileX(indexFilePath); my::DeleteFileX(v0IndexFilePath); } + +UNIT_TEST(UGC_NoReviews) +{ + auto & builder = MwmBuilder::Builder(); + Storage s(builder.GetDataSource()); + s.Load(); + s.SaveIndex(); + // When we didn't write any reviews there should be no index file and no ugc file. + TEST(!DeleteIndexFile(), ()); + TEST(!DeleteUGCFile(), ()); +}