Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions model/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,35 +304,48 @@ int main(int argc, char* argv[])
} catch (const OM::util::cmd_exception& e) {
if( e.getCode() == 0 ){
// this is not an error, but exiting due to command line
cerr << e.what() << "; exiting..." << endl;
std::cerr << e.what() << "; exiting..." << endl;
}else{
cerr << "Command-line error: "<<e.what();
std::cerr << "Command-line error: "<<e.what();
exitStatus = e.getCode();
}
} catch (const ::xsd::cxx::tree::exception<char>& e) {
cerr << "XSD error: " << e.what() << '\n' << e << endl;
if (errno == 2) // Errno value 2 corresponds to "No such file or directory" i.e. this is not a mismatch between scenario contents and schema rules.
{
// We don't print the content of the xsdcxx exception since the error messages are not relevant to the user in this case.
std::cerr << "Parsing scenario file failed.\n\tLikely the XSD schema file is not present at an expected location/with expected filename." << std::endl;
}
else
{
// e.what() returns a concise error message e.g. "instance document parsing failed".
// Whereas inserting e into a stream inserts the (possibly long and repetitive) list of error messages arising from the parsing attempt.
std::cerr << "XSD error: " << e.what() << '\n' << e << endl;

// We print this *after* the above since users are more likely to take note of the tail of stderr/stdout output than the head.
std::cerr << "Parsing scenario file failed.\n\tLikely the XSD schema is named/located correctly but the scenario does not conform to the schema." << std::endl;
}
exitStatus = OM::util::Error::XSD;
} catch (const OM::util::checkpoint_error& e) {
cerr << "Checkpoint error: " << e.what() << endl;
cerr << e << flush;
std::cerr << "Checkpoint error: " << e.what() << endl;
std::cerr << e << flush;
exitStatus = e.getCode();
} catch (const OM::util::traced_exception& e) {
cerr << "Code error: " << e.what() << endl;
cerr << e << flush;
cerr << "This is likely an error in the C++ code. Please report!" << endl;
std::cerr << "Code error: " << e.what() << endl;
std::cerr << e << flush;
std::cerr << "This is likely an error in the C++ code. Please report!" << endl;
exitStatus = e.getCode();
} catch (const OM::util::xml_scenario_error& e) {
cerr << "Error: " << e.what() << endl;
cerr << "In: " << scenarioFile << endl;
std::cerr << "Error: " << e.what() << endl;
std::cerr << "In: " << scenarioFile << endl;
exitStatus = e.getCode();
} catch (const OM::util::base_exception& e) {
cerr << "Error: " << e.message() << endl;
std::cerr << "Error: " << e.message() << endl;
exitStatus = e.getCode();
} catch (const exception& e) {
cerr << "Error: " << e.what() << endl;
std::cerr << "Error: " << e.what() << endl;
exitStatus = EXIT_FAILURE;
} catch (...) {
cerr << "Unknown error" << endl;
std::cerr << "Unknown error" << endl;
exitStatus = EXIT_FAILURE;
}

Expand Down
14 changes: 7 additions & 7 deletions model/util/DocumentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ namespace OM
{
namespace util
{
unique_ptr<scnXml::Scenario> loadScenario(std::string lXmlFile)
std::unique_ptr<scnXml::Scenario> loadScenario(std::string lXmlFile)
{
// Opening by filename causes a schema lookup in the scenario file's dir,
// which does always work. Opening with a stream uses the working directory.

// Note that the schema location can be set manually by passing properties,
// but we won't necessarily have the right schema version associated with
// the XML file in that case.
ifstream fileStream(lXmlFile.c_str(), ios::binary);
std::ifstream fileStream(lXmlFile.c_str(), ios::binary);
if (!fileStream.good())
{
string msg = "Error: unable to open " + lXmlFile;
std::string msg = "Error: unable to open " + lXmlFile;
throw util::xml_scenario_error(msg);
}
unique_ptr<scnXml::Scenario> scenario = scnXml::parseScenario (fileStream);
std::unique_ptr<scnXml::Scenario> scenario = scnXml::parseScenario (fileStream);
fileStream.close ();

int scenarioVersion = scenario->getSchemaVersion();
const int scenarioVersion = scenario->getSchemaVersion();

if (scenarioVersion < SCHEMA_VERSION) {
// Don't bother aborting. Mostly if something really is incompatible
// loading will not succeed anyway.
cerr<<"Warning: "<<lXmlFile<<" uses an old schema version (latest is "<<SCHEMA_VERSION<<")."<<endl;
std::cerr<<"Warning: "<<lXmlFile<<" uses an old schema version (latest is "<<SCHEMA_VERSION<<")."<<endl;
}
else if (scenarioVersion > SCHEMA_VERSION)
throw util::xml_scenario_error ("Error: new schema version unsupported");

return scenario;
}
}
}
}
2 changes: 1 addition & 1 deletion model/util/DocumentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace OM
{
static const int SCHEMA_VERSION = 48;

unique_ptr<scnXml::Scenario> loadScenario(std::string lXmlFile);
std::unique_ptr<scnXml::Scenario> loadScenario(std::string lXmlFile);
}
}

Expand Down
Loading