From 7d8853ea7c98f08a84f0bec04d9aab4e07c674e1 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Wed, 28 Jun 2017 16:00:02 +0300 Subject: [PATCH] [OPENLR] Report more errors. --- openlr/openlr_sample.cpp | 24 ++++++++++++++++++++--- openlr/openlr_stat/openlr_stat.cpp | 31 +++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/openlr/openlr_sample.cpp b/openlr/openlr_sample.cpp index 68efa6f9ee..76d4248766 100644 --- a/openlr/openlr_sample.cpp +++ b/openlr/openlr_sample.cpp @@ -26,16 +26,28 @@ void ParseMWMSegments(std::string const & line, uint32_t const lineNumber, uint32_t featureIndex; if (!strings::to_uint(segParts[1], featureIndex)) - MYTHROW(openlr::SamplePoolLoadError, ("Can't parse MWMSegment", seg, "line:", lineNumber)); + { + MYTHROW(openlr::SamplePoolLoadError, ("Can't parse feature index of MWMSegment: uint expected", + seg, "uint expected, got:", segParts[1], + "line:", lineNumber)); + } uint32_t segId; if (!strings::to_uint(segParts[2], segId)) - MYTHROW(openlr::SamplePoolLoadError, ("Can't parse MWMSegment", seg, "line:", lineNumber)); + { + MYTHROW(openlr::SamplePoolLoadError, ("Can't parse segment id of MWMSegment:", + seg, "uint expected, got:", segParts[2], + "line:", lineNumber)); + } bool const isForward = (segParts[3] == "fwd"); double length = 0; if (!strings::to_double(segParts[4], length)) - MYTHROW(openlr::SamplePoolLoadError, ("Can't parse MWMSegment", seg, "line:", lineNumber)); + { + MYTHROW(openlr::SamplePoolLoadError, ("Can't parse segment length of MWMSegment:", + seg, "double expected, got:", segParts[4], + "line:", lineNumber)); + } segments.push_back({FeatureID(mwmId, featureIndex), segId, isForward, length}); } @@ -124,6 +136,12 @@ SamplePool LoadSamplePool(std::string const & fileName, Index const & index) pool.push_back(item); } + if (sample.fail() && !sample.eof()) + MYTHROW(SamplePoolLoadError, ("Can't read from file", fileName, strerror(errno))); + + if (pool.empty()) + MYTHROW(SamplePoolLoadError, ("No sample is read,", fileName, "probably empty")); + return pool; } diff --git a/openlr/openlr_stat/openlr_stat.cpp b/openlr/openlr_stat/openlr_stat.cpp index 3cfbe60e18..d8c6024d4c 100644 --- a/openlr/openlr_stat/openlr_stat.cpp +++ b/openlr/openlr_stat/openlr_stat.cpp @@ -9,12 +9,14 @@ #include "coding/file_name_utils.hpp" -#include "std/cstdint.hpp" -#include "std/cstdio.hpp" -#include "std/vector.hpp" - #include "3party/gflags/src/gflags/gflags.h" +#include +#include +#include + +#include + DEFINE_string(input, "", "Path to OpenLR file."); DEFINE_string(output, "output.txt", "Path to output file"); DEFINE_string(mwms_path, "", "Path to a folder with mwms."); @@ -30,13 +32,24 @@ namespace const int32_t kMinNumThreads = 1; const int32_t kMaxNumThreads = 128; -void LoadIndexes(string const & pathToMWMFolder, vector & indexes) +bool IsDirectory(std::string const & path) { + struct ::stat st; + stat(path.data(), &st); + return S_ISDIR(st.st_mode); +} + +void LoadIndexes(std::string const & pathToMWMFolder, std::vector & indexes) +{ + CHECK(IsDirectory(pathToMWMFolder), (pathToMWMFolder, "must be a directory.")); + Platform::FilesList files; - Platform::GetFilesByRegExp(pathToMWMFolder, string(".*\\") + DATA_FILE_EXTENSION, files); + Platform::GetFilesByRegExp(pathToMWMFolder, std::string(".*\\") + DATA_FILE_EXTENSION, files); + + CHECK(!files.empty(), (pathToMWMFolder, "Contains no .mwm files.")); size_t const numIndexes = indexes.size(); - vector numCountries(numIndexes); + std::vector numCountries(numIndexes); for (auto const & fileName : files) { @@ -98,7 +111,7 @@ bool ValidateNumThreads(char const * flagname, int32_t value) return true; } -bool ValidataMwmPath(char const * flagname, string const & value) +bool ValidataMwmPath(char const * flagname, std::string const & value) { if (value.empty()) { @@ -124,7 +137,7 @@ int main(int argc, char * argv[]) auto const numThreads = static_cast(FLAGS_num_threads); - vector indexes(numThreads); + std::vector indexes(numThreads); LoadIndexes(FLAGS_mwms_path, indexes); OpenLRSimpleDecoder::SegmentsFilter filter(FLAGS_ids_path, FLAGS_multipoints_only);