Commit 7f533666 by Maarten L. Hekkelman

Error reporting

parent e44539ef
......@@ -746,34 +746,22 @@ void category::set_validator(const validator *v, datablock &db)
{
std::set<std::string> missing;
std::vector<uint16_t> kix;
for (auto k : m_cat_validator->m_keys)
if (not empty())
{
kix.push_back(get_column_ix(k));
if (kix.back() >= m_columns.size())
missing.insert(k);
std::vector<uint16_t> kix;
for (auto k : m_cat_validator->m_keys)
{
kix.push_back(get_column_ix(k));
if (kix.back() >= m_columns.size())
missing.insert(k);
}
}
// TODO: perhaps reintroduce the following check?
// if (missing.empty())
// {
// // First check if all records do have their mandatory fields
// for (auto r : *this)
// {
// for (auto ix : kix)
// {
// if (r[ix].empty())
// missing.insert(m_columns[ix].m_name);
// }
// }
// }
if (missing.size() == 1)
throw std::runtime_error("Cannot construct index since the key field " + *missing.begin() + " in " + m_name + " is empty");
if (not missing.empty())
throw std::runtime_error("Cannot construct index since the key fields " + cif::join(missing, ", ") + " in " + m_name + " are empty");
m_index = new category_index(this);
if (missing.empty())
m_index = new category_index(this);
else if (VERBOSE > 0)
std::cerr << "Cannot construct index since the key field" << (missing.size() > 1 ? "s" : "") << " "
<< cif::join(missing, ", ") + " in " + m_name + " " + (missing.size() == 1 ? "is" : "are") << " missing" << std::endl;
}
}
else
......@@ -854,6 +842,20 @@ bool category::is_valid() const
result = false;
}
if (m_cat_validator->m_keys.empty() == false and m_index == nullptr)
{
std::set<std::string> missing;
for (auto k : m_cat_validator->m_keys)
{
if (get_column_ix(k) >= m_columns.size())
missing.insert(k);
}
m_validator->report_error("In category " + m_name + " the index is missing, likely due to missing key fields: " + join(missing, ", "), false);
result = false;
}
#if not defined(NDEBUG)
// check index?
if (m_index)
......
......@@ -183,10 +183,18 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name)
void file::load(const std::filesystem::path &p)
{
gxrio::ifstream in(p);
if (not in.is_open())
throw std::runtime_error("Could not open file " + p.string());
load(in);
try
{
gxrio::ifstream in(p);
if (not in.is_open())
throw std::runtime_error("Could not open file " + p.string());
load(in);
}
catch (const std::exception &ex)
{
throw_with_nested(std::runtime_error("Error reading file " + p.string()));
}
}
void file::load(std::istream &is)
......
......@@ -6223,11 +6223,18 @@ file read(std::istream &is)
file read(const std::filesystem::path &file)
{
gxrio::ifstream in(file);
if (not in.is_open())
throw std::runtime_error("Could not open file " + file.string() + " for input");
return read(in);
try
{
gxrio::ifstream in(file);
if (not in.is_open())
throw std::runtime_error("Could not open file " + file.string() + " for input");
return read(in);
}
catch (const std::exception &ex)
{
throw_with_nested(std::runtime_error("Error reading file " + file.string()));
}
}
} // namespace pdbx
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment