From 428d9bf093987dbb207aacef4915ac968ecb0538 Mon Sep 17 00:00:00 2001 From: Denis Levchenko Date: Tue, 24 Nov 2020 17:15:02 +0500 Subject: [PATCH] Process missing leap speeds file --- generator/region_meta.cpp | 57 ++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/generator/region_meta.cpp b/generator/region_meta.cpp index cae9ba187f..12574837c8 100644 --- a/generator/region_meta.cpp +++ b/generator/region_meta.cpp @@ -29,36 +29,43 @@ namespace feature { bool ReadRegionDataImpl(std::string const & countryName, RegionData & data) { - try + if (Platform::IsFileExistsByFullPath(LEAP_SPEEDS_FILE)) { - auto crossMwmDataReader = GetPlatform().GetReader(LEAP_SPEEDS_FILE); - std::string crossMwmDataBuffer; - crossMwmDataReader->ReadAsString(crossMwmDataBuffer); - base::Json crossMwmData(crossMwmDataBuffer.data()); - - json_t const * crossMwmJsonData = nullptr; - FromJSONObjectOptionalField(crossMwmData.get(), countryName, crossMwmJsonData); - if (crossMwmJsonData) + try { - double leapSpeed = FromJSONObject(crossMwmJsonData, "leapspeed"); - if (leapSpeed > 0.0) - data.SetLeapWeightSpeed(leapSpeed); + auto crossMwmDataReader = GetPlatform().GetReader(LEAP_SPEEDS_FILE); + std::string crossMwmDataBuffer; + crossMwmDataReader->ReadAsString(crossMwmDataBuffer); + base::Json crossMwmData(crossMwmDataBuffer.data()); + + json_t const * crossMwmJsonData = nullptr; + FromJSONObjectOptionalField(crossMwmData.get(), countryName, crossMwmJsonData); + if (crossMwmJsonData) + { + double leapSpeed = FromJSONObject(crossMwmJsonData, "leapspeed"); + if (leapSpeed > 0.0) + data.SetLeapWeightSpeed(leapSpeed); + } + } + catch (FileAbsentException const & e) + { + LOG(LERROR, ("Error missing file", LEAP_SPEEDS_FILE, ":", e.Msg())); + return false; + } + catch (Reader::Exception const & e) + { + LOG(LWARNING, ("Error reading", LEAP_SPEEDS_FILE, ":", e.Msg())); + return false; + } + catch (base::Json::Exception const & e) + { + LOG(LERROR, ("Error parsing JSON in", LEAP_SPEEDS_FILE, ":", e.Msg())); + return false; } } - catch (FileAbsentException const & e) + else { - LOG(LERROR, ("Error missing file", LEAP_SPEEDS_FILE, ":", e.Msg())); - return false; - } - catch (Reader::Exception const & e) - { - LOG(LWARNING, ("Error reading", LEAP_SPEEDS_FILE, ":", e.Msg())); - return false; - } - catch (base::Json::Exception const & e) - { - LOG(LERROR, ("Error parsing JSON in", LEAP_SPEEDS_FILE, ":", e.Msg())); - return false; + LOG(LWARNING, ("File", LEAP_SPEEDS_FILE, "not found.")); } try