diff --git a/src/mappings.cpp b/src/mappings.cpp index 6795b23..56235f5 100644 --- a/src/mappings.cpp +++ b/src/mappings.cpp @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -21,22 +23,30 @@ Mappings Mappings::load() { // load mappings fs::directory_iterator end_itr; - for (fs::directory_iterator itr("mappings"); itr != end_itr; ++itr) { - if (fs::is_directory(itr->status()) || - !boost::algorithm::ends_with(itr->path().string(), ".csv")) - continue; - - csv::CsvReader csv(itr->path().string()); - - std::vector l; - while (csv >> l) { - if (l.size() < 2) { - BOOST_LOG_TRIVIAL(warning) << "found invalid mapping"; + try { + for (fs::directory_iterator itr("mappings"); itr != end_itr; ++itr) { + if (fs::is_directory(itr->status()) || + !boost::algorithm::ends_with(itr->path().string(), ".csv")) continue; + + csv::CsvReader csv(itr->path().string()); + + std::vector l; + while (csv >> l) { + if (l.size() < 2) { + BOOST_LOG_TRIVIAL(warning) << "found invalid mapping"; + continue; + } + mappings[l[0]] = {l[0], l[1], + l.size() >= 4 ? std::optional(l[3]) : std::nullopt}; } - mappings[l[0]] = {l[0], l[1], - l.size() >= 4 ? std::optional(l[3]) : std::nullopt}; } + } catch (boost::filesystem::filesystem_error &e) { + if (e.code() == boost::system::errc::no_such_file_or_directory) { + throw std::runtime_error( + std::string("The mappings directory is missing!\n") + e.what()); + } + throw; } if (fs::is_regular_file("renames.csv")) { @@ -51,6 +61,8 @@ Mappings Mappings::load() { renames[l[0]] = l[1]; } + } else { + BOOST_LOG_TRIVIAL(warning) << "no renames found, skipping"; } BOOST_LOG_TRIVIAL(info) << "loaded " << mappings.size() << " mappings and "