Skip to content
Snippets Groups Projects
Commit 279a7716 authored by Martin Killenberg's avatar Martin Killenberg
Browse files

ScriptedInitialisationHandler: catch boost exceptions and throw ChimeraTK...

ScriptedInitialisationHandler: catch boost exceptions and throw ChimeraTK logic_error with improved what() message
parent c4a0d35c
No related branches found
No related tags found
No related merge requests found
......@@ -23,37 +23,44 @@ namespace ChimeraTK {
_scriptOutput.value = "";
_scriptOutput.value.write();
bp::ipstream out;
bp::child initScript(_command, (bp::std_out & bp::std_err) > out);
std::string line;
// Publish every line that is read from the script. It is appended to the output string
// such that a growing message is published.
// For debugging it is important to get the intermediate information. In case the script gets stuck
// you want to know what has already been printed.
while(initScript.running() && std::getline(out, line)) {
output += line + "\n";
_scriptOutput.value = output;
_scriptOutput.value.write();
}
initScript.wait();
try {
bp::ipstream out;
bp::child initScript(_command, (bp::std_out & bp::std_err) > out);
std::string line;
// Publish every line that is read from the script. It is appended to the output string
// such that a growing message is published.
// For debugging it is important to get the intermediate information. In case the script gets stuck
// you want to know what has already been printed.
while(initScript.running() && std::getline(out, line)) {
output += line + "\n";
_scriptOutput.value = output;
_scriptOutput.value.write();
}
initScript.wait();
if(initScript.exit_code() != 0) {
output += "!!! " + _deviceAlias + " initialisation FAILED!";
_scriptOutput.value = output;
_scriptOutput.value.write();
if(!_lastFailed) {
if(initScript.exit_code() != 0) {
output += "!!! " + _deviceAlias + " initialisation FAILED!";
_scriptOutput.value = output;
_scriptOutput.value.write();
if(!_lastFailed) {
std::cerr << output << std::endl;
}
_lastFailed = true;
std::this_thread::sleep_for(std::chrono::seconds(_errorGracePeriod));
throw ChimeraTK::runtime_error(_deviceAlias + " board initialisation failed.");
}
else {
output += _deviceAlias + " initialisation SUCCESS!";
_scriptOutput.value = output;
_scriptOutput.value.write();
std::cerr << output << std::endl;
_lastFailed = false;
}
_lastFailed = true;
std::this_thread::sleep_for(std::chrono::seconds(_errorGracePeriod));
throw ChimeraTK::runtime_error(_deviceAlias + " board initialisation failed.");
}
else {
output += _deviceAlias + " initialisation SUCCESS!";
_scriptOutput.value = output;
_scriptOutput.value.write();
std::cerr << output << std::endl;
_lastFailed = false;
catch(bp::process_error& e) {
// this
throw ChimeraTK::logic_error("Caught boost::process::process_error while executing \"" + _command +
"\" for device " + _deviceAlias + ": " + e.what());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment