Skip to content
Snippets Groups Projects
Unverified Commit 74dea35c authored by Xavier Robin's avatar Xavier Robin
Browse files

fix: raise clean error if date is invalid

This avoids ignoring issues in optimized builds and hard to read errors in
unoptimized builds.
parent 02bda329
Branches
Tags
No related merge requests found
......@@ -90,6 +90,7 @@ int main(int argc, char const *argv[])
filtered_istream.push(boost::iostreams::gzip_decompressor());
}
filtered_istream.push(istream);
try {
io::ChemdictParser cdp(filtered_istream, dialect, ignore_reserved, ignore_obsolete);
conop::CompoundLibPtr compound_lib;
bool in_mem=false;
......@@ -118,5 +119,10 @@ int main(int argc, char const *argv[])
<< strerror(errno) << std::endl;
return 1;
}
}
catch (ost::Error const &err) {
std::cerr << "Error: " << err.what() << std::endl;
return 1;
}
return 0;
}
......@@ -23,6 +23,8 @@
#include <map>
#include <boost/shared_ptr.hpp>
#include <ost/string_ref.hh>
#include <ost/message.hh>
#include <ost/log.hh>
#include <ost/conop/module_config.hh>
#include <ost/mol/chem_class.hh>
......@@ -54,11 +56,19 @@ struct DLLEXPORT_OST_CONOP Date {
static Date FromString(const StringRef& str)
{
std::vector<StringRef> parts=str.split('-');
assert(parts.size()==3);
if (parts.size() != 3) {
std::stringstream msg;
msg << "Invalid date string: '" << str << "'";
throw ost::Error(msg.str());
}
std::pair<bool, int> year=parts[0].to_int();
std::pair<bool, int> month=parts[1].to_int();
std::pair<bool, int> day=parts[2].to_int();
assert(year.first); assert(month.first); assert(day.first);
if (! year.first || ! month.first || ! day.first) {
std::stringstream msg;
msg << "Invalid date string: '" << str << "'";
throw ost::Error(msg.str());
}
return Date(year.second, month.second, day.second);
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment