Skip to content

Commit

Permalink
Use mef::errinfo_container for MEF errors
Browse files Browse the repository at this point in the history
MEF containers can act as namespaces
to clarify the error location.
This is currently used for event trees.

Issue #219
  • Loading branch information
rakhimov committed Oct 15, 2017
1 parent 1a54a23 commit c898890
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ struct SettingsError : public Error {

namespace mef { // MEF specific errors.

/// The MEF container element as namespace.
using errinfo_container = boost::error_info<struct tag_contianer, std::string>;

/// For validating input parameters or user arguments.
struct ValidityError : public Error {
using Error::Error;
Expand Down
8 changes: 4 additions & 4 deletions src/initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void Initializer::DefineBranchTarget(const xml::Element& target_node,
event_tree->Add(std::move(fork));
(*it)->usage(true);
} catch (ValidityError& err) {
err.msg("In event tree " + event_tree->name() + ", " + err.msg());
err << errinfo_container("Event tree '" + event_tree->name() + "'");
throw;
}
} else {
Expand Down Expand Up @@ -1541,7 +1541,7 @@ void Initializer::ValidateInitialization() {
try {
cycle::CheckCycle<NamedBranch>(event_tree->branches(), "branch");
} catch (CycleError& err) {
err.msg("In event tree " + event_tree->name() + ", " + err.msg());
err << errinfo_container("Event tree '" + event_tree->name() + "'");
throw;
}
}
Expand All @@ -1556,7 +1556,7 @@ void Initializer::ValidateInitialization() {
CheckFunctionalEventOrder(event_tree->initial_state());
EnsureLinksOnlyInSequences(event_tree->initial_state());
} catch (ValidityError& err) {
err.msg("In event tree " + event_tree->name() + ", " + err.msg());
err << errinfo_container("Event tree '" + event_tree->name() + "'");
throw;
}
}
Expand All @@ -1572,7 +1572,7 @@ void Initializer::ValidateInitialization() {
}
EnsureHomogeneousEventTree(event_tree->initial_state());
} catch (ValidityError& err) {
err.msg("In event tree " + event_tree->name() + ", " + err.msg());
err << errinfo_container("Event tree '" + event_tree->name() + "'");
throw;
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/scram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,12 @@ int main(int argc, char* argv[]) {

#ifdef NDEBUG
} catch (const scram::IOError& err) {
std::cerr << boost::core::demangled_name(typeid(err)) << "\n";
LOG(scram::DEBUG1) << boost::diagnostic_information(err);
std::cerr << boost::core::demangled_name(typeid(err)) << "\n\n";
const std::string* filename =
boost::get_error_info<boost::errinfo_file_name>(err);
assert(filename);
std::cerr << "\nFile: " << *filename << "\n";
std::cerr << "File: " << *filename << "\n";
if (const std::string* mode =
boost::get_error_info<boost::errinfo_file_open_mode>(err)) {
std::cerr << "Open mode: " << *mode << "\n";
Expand All @@ -327,13 +328,18 @@ int main(int argc, char* argv[]) {
std::cerr << "\n" << err.what() << std::endl;
return 1;
} catch (const scram::Error& err) {
std::cerr << boost::core::demangled_name(typeid(err)) << "\n";
LOG(scram::DEBUG1) << boost::diagnostic_information(err);
std::cerr << boost::core::demangled_name(typeid(err)) << "\n\n";
if (const std::string* filename =
boost::get_error_info<boost::errinfo_file_name>(err)) {
std::cerr << "\nFile: " << *filename << "\n";
std::cerr << "File: " << *filename << "\n";
if (const int* line = boost::get_error_info<boost::errinfo_at_line>(err))
std::cerr << "Line: " << *line << "\n";
}
if (const std::string* container =
boost::get_error_info<scram::mef::errinfo_container>(err)) {
std::cerr << "MEF Container: " << *container << "\n";
}
std::cerr << "\n" << err.what() << std::endl;
return 1;
} catch (const boost::exception& boost_err) {
Expand Down

0 comments on commit c898890

Please sign in to comment.