Skip to content

Commit 3927fac

Browse files
committed
DPL: improve exception handling
1 parent 667a69c commit 3927fac

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

Framework/Core/include/Framework/runDataProcessing.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include "Framework/CustomWorkflowTerminationHook.h"
2222
#include "Framework/CommonServices.h"
2323
#include "Framework/WorkflowCustomizationHelpers.h"
24+
#include "Framework/RuntimeError.h"
2425
#include "Framework/Logger.h"
2526

26-
#include <unistd.h>
2727
#include <vector>
2828
#include <cstring>
2929
#include <exception>
@@ -121,6 +121,9 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& specs,
121121
o2::framework::ConfigContext& configContext);
122122

123123
void doBoostException(boost::exception& e);
124+
void doDPLException(o2::framework::RuntimeErrorRef& ref);
125+
void doUnknownException(std::string const& s);
126+
void doDefaultWorkflowTerminationHook();
124127

125128
int main(int argc, char** argv)
126129
{
@@ -171,9 +174,11 @@ int main(int argc, char** argv)
171174
} catch (boost::exception& e) {
172175
doBoostException(e);
173176
} catch (std::exception const& error) {
174-
LOG(ERROR) << "error while setting up workflow: " << error.what();
177+
doUnknownException(error.what());
178+
} catch (o2::framework::RuntimeErrorRef& ref) {
179+
doDPLException(ref);
175180
} catch (...) {
176-
LOG(ERROR) << "Unknown error while setting up workflow.";
181+
doUnknownException("");
177182
}
178183

179184
char* idstring = nullptr;
@@ -186,7 +191,7 @@ int main(int argc, char** argv)
186191
o2::framework::OnWorkflowTerminationHook onWorkflowTerminationHook;
187192
UserCustomizationsHelper::userDefinedCustomization(onWorkflowTerminationHook, 0);
188193
onWorkflowTerminationHook(idstring);
189-
LOG(INFO) << "Process " << getpid() << " is exiting.";
194+
doDefaultWorkflowTerminationHook();
190195
return result;
191196
}
192197

Framework/Core/src/runDataProcessing.cxx

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,32 @@ bool processSigChild(DeviceInfos& infos)
741741
return hasError;
742742
}
743743

744+
void doDPLException(RuntimeErrorRef& e)
745+
{
746+
auto& err = o2::framework::error_from_ref(e);
747+
if (err.maxBacktrace != 0) {
748+
LOG(ERROR) << "Unhandled o2::framework::runtime_error reached the top of main, device shutting down. Details follow: \n";
749+
backtrace_symbols_fd(err.backtrace, err.maxBacktrace, STDERR_FILENO);
750+
} else {
751+
LOG(ERROR) << "Unhandled o2::framework::runtime_error reached the top of main, device shutting down."
752+
" Recompile with DPL_ENABLE_BACKTRACE=1 to get more information.";
753+
}
754+
}
755+
756+
void doUnknownException(std::string const& s)
757+
{
758+
if (s.empty()) {
759+
LOG(ERROR) << "Unknown error while setting up workflow.";
760+
} else {
761+
LOG(ERROR) << "error while setting up workflow: " << s;
762+
}
763+
}
764+
765+
void doDefaultWorkflowTerminationHook()
766+
{
767+
//LOG(INFO) << "Process " << getpid() << " is exiting.";
768+
}
769+
744770
int doChild(int argc, char** argv, ServiceRegistry& serviceRegistry, const o2::framework::DeviceSpec& spec, TerminationPolicy errorPolicy,
745771
uv_loop_t* loop)
746772
{
@@ -808,14 +834,7 @@ int doChild(int argc, char** argv, ServiceRegistry& serviceRegistry, const o2::f
808834
<< boost::current_exception_diagnostic_information(true);
809835
return 1;
810836
} catch (o2::framework::RuntimeErrorRef e) {
811-
auto& err = o2::framework::error_from_ref(e);
812-
if (err.maxBacktrace != 0) {
813-
LOG(ERROR) << "Unhandled o2::framework::runtime_error reached the top of main, device shutting down. Details follow: \n";
814-
backtrace_symbols_fd(err.backtrace, err.maxBacktrace, STDERR_FILENO);
815-
} else {
816-
LOG(ERROR) << "Unhandled o2::framework::runtime_error reached the top of main, device shutting down."
817-
" Recompile with DPL_ENABLE_BACKTRACE=1 to get more information.";
818-
}
837+
doDPLException(e);
819838
return 1;
820839
} catch (std::exception& e) {
821840
LOG(ERROR) << "Unhandled std::exception reached the top of main: " << e.what() << ", device shutting down.";
@@ -1161,16 +1180,26 @@ int runStateMachine(DataProcessorSpecs const& workflow,
11611180
}
11621181
break;
11631182
case DriverState::MERGE_CONFIGS: {
1164-
controls.resize(deviceSpecs.size());
1165-
deviceExecutions.resize(deviceSpecs.size());
1166-
1167-
DeviceSpecHelpers::reworkShmSegmentSize(dataProcessorInfos);
1168-
DeviceSpecHelpers::prepareArguments(driverControl.defaultQuiet,
1169-
driverControl.defaultStopped,
1170-
dataProcessorInfos,
1171-
deviceSpecs,
1172-
deviceExecutions, controls,
1173-
driverInfo.uniqueWorkflowId);
1183+
try {
1184+
controls.resize(deviceSpecs.size());
1185+
deviceExecutions.resize(deviceSpecs.size());
1186+
1187+
DeviceSpecHelpers::reworkShmSegmentSize(dataProcessorInfos);
1188+
DeviceSpecHelpers::prepareArguments(driverControl.defaultQuiet,
1189+
driverControl.defaultStopped,
1190+
dataProcessorInfos,
1191+
deviceSpecs,
1192+
deviceExecutions, controls,
1193+
driverInfo.uniqueWorkflowId);
1194+
} catch (o2::framework::RuntimeErrorRef& ref) {
1195+
auto& err = o2::framework::error_from_ref(ref);
1196+
LOG(ERROR) << "Unable to merge configurations: " << err.what;
1197+
#ifdef DPL_ENABLE_BACKTRACE
1198+
std::cerr << "\nStacktrace follows:\n\n";
1199+
backtrace_symbols_fd(err.backtrace, err.maxBacktrace, STDERR_FILENO);
1200+
#endif
1201+
return 1;
1202+
}
11741203

11751204
} break;
11761205
case DriverState::SCHEDULE: {

0 commit comments

Comments
 (0)