feat: improve error messages
This commit is contained in:
parent
531c918ba5
commit
55ad862ba4
|
@ -5,7 +5,9 @@
|
|||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/directory.hpp>
|
||||
#include <boost/filesystem/exception.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/system/detail/errc.hpp>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
|
@ -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<std::string> 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<std::string> 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 "
|
||||
|
|
Loading…
Reference in New Issue