Skip to content

Commit

Permalink
Rename JException metadata
Browse files Browse the repository at this point in the history
Now uses (function_name, type_name, instance_name, plugin_name) which make sense for all components
  • Loading branch information
nathanwbrei committed May 3, 2024
1 parent cace1ad commit 808fd9d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 63 deletions.
4 changes: 3 additions & 1 deletion src/libraries/JANA/JEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ class JEventSource : public jana::omni::JComponent, public jana::omni::JHasOutpu
else if (rs == RETURN_STATUS::kERROR || rs == RETURN_STATUS::kUNKNOWN) {
JException ex ("JEventSource threw RETURN_STATUS::kERROR or kUNKNOWN");
ex.plugin_name = m_plugin_name;
ex.component_name = m_type_name;
ex.type_name = m_type_name;
ex.function_name = "JEventSource::GetEvent";
ex.instance_name = m_resource_name;
throw ex;
}
else {
Expand Down
26 changes: 12 additions & 14 deletions src/libraries/JANA/JException.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ struct JException : public std::exception {

/// Convenience method for formatting complete error data
inline friend std::ostream& operator<<(std::ostream& os, JException const& ex) {
os << "Exception: " << ex.message << std::endl;
if (ex.callback_name.length() != 0) {
os << " Callback: " << ex.callback_name << std::endl;
os << "JException" << std::endl;
os << " Message: " << ex.message << std::endl;
if (ex.function_name.length() != 0) {
os << " Function: " << ex.function_name << std::endl;
}
if (ex.component_name.length() != 0) {
os << " Component: " << ex.component_name << std::endl;
if (ex.type_name.length() != 0) {
os << " Class: " << ex.type_name << std::endl;
}
if (ex.factory_name.length() != 0) {
os << " Factory name: " << ex.factory_name << std::endl;
os << " Factory tag: " << ex.factory_tag << std::endl;
if (ex.instance_name.length() != 0) {
os << " Instance: " << ex.instance_name << std::endl;
}
if (ex.plugin_name.length() != 0) {
os << " Plugin: " << ex.plugin_name << std::endl;
os << " Plugin: " << ex.plugin_name << std::endl;
}
if (ex.stacktrace.length() != 0 && ex.show_stacktrace) {
os << " Backtrace:" << std::endl << std::endl << ex.stacktrace;
Expand All @@ -67,11 +67,9 @@ struct JException : public std::exception {

std::string message;
std::string plugin_name;
std::string component_name;
std::string callback_name;
std::string component_prefix;
std::string factory_name;
std::string factory_tag;
std::string type_name;
std::string function_name;
std::string instance_name;
std::string stacktrace;
std::exception_ptr nested_exception;
bool show_stacktrace=true;
Expand Down
67 changes: 35 additions & 32 deletions src/libraries/JANA/JFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ void JFactory::Create(const std::shared_ptr<const JEvent>& event) {
mStatus = Status::Unprocessed;
}
catch (JException& ex) {
std::string instanceName = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
if (ex.function_name.empty()) ex.function_name = "JFactory::Init";
if (ex.type_name.empty()) ex.type_name = mFactoryName;
if (ex.instance_name.empty()) ex.instance_name = instanceName;
if (ex.plugin_name.empty()) ex.plugin_name = mPluginName;
if (ex.component_name.empty()) ex.component_name = mFactoryName;
if (ex.factory_name.empty()) ex.factory_name = mFactoryName;
if (ex.factory_tag.empty()) ex.factory_tag = mTag;
throw ex;
}
catch (std::exception& e) {
auto ex = JException("Exception in JFactoryT::Init(): %s", e.what());
ex.nested_exception = std::current_exception();
ex.function_name = "JFactory::Init";
ex.type_name = mFactoryName;
ex.instance_name = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
ex.plugin_name = mPluginName;
ex.component_name = mFactoryName;
ex.factory_name = mFactoryName;
ex.factory_tag = mTag;
throw ex;
}
catch (...) {
auto ex = JException("Unknown exception in JFactoryT::Init()");
auto ex = JException("Unknown exception");
ex.nested_exception = std::current_exception();
ex.function_name = "JFactory::Init";
ex.type_name = mFactoryName;
ex.instance_name = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
ex.plugin_name = mPluginName;
ex.component_name = mFactoryName;
ex.factory_name = mFactoryName;
ex.factory_tag = mTag;
throw ex;
}
}
Expand All @@ -66,56 +67,58 @@ void JFactory::Create(const std::shared_ptr<const JEvent>& event) {
}
}
catch (JException& ex) {
std::string instanceName = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
if (ex.function_name.empty()) ex.function_name = "JFactory::BeginRun/ChangeRun/EndRun(";
if (ex.type_name.empty()) ex.type_name = mFactoryName;
if (ex.instance_name.empty()) ex.instance_name = instanceName;
if (ex.plugin_name.empty()) ex.plugin_name = mPluginName;
if (ex.component_name.empty()) ex.component_name = mFactoryName;
if (ex.factory_name.empty()) ex.factory_name = mFactoryName;
if (ex.factory_tag.empty()) ex.factory_tag = mTag;
throw ex;
}
catch (std::exception& e) {
auto ex = JException("Exception in JFactory::BeginRun/ChangeRun/EndRun(): %s", e.what());
auto ex = JException(e.what());
ex.nested_exception = std::current_exception();
ex.function_name = "JFactory::BeginRun/ChangeRun/EndRun";
ex.type_name = mFactoryName;
ex.instance_name = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
ex.plugin_name = mPluginName;
ex.component_name = mFactoryName;
ex.factory_name = mFactoryName;
ex.factory_tag = mTag;
throw ex;
}
catch (...) {
auto ex = JException("Unknown exception in JFactory::BeginRun/ChangeRun/EndRun()");
auto ex = JException("Unknown exception");
ex.nested_exception = std::current_exception();
ex.function_name = "JFactory::BeginRun/ChangeRun/EndRun";
ex.type_name = mFactoryName;
ex.instance_name = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
ex.plugin_name = mPluginName;
ex.component_name = mFactoryName;
ex.factory_name = mFactoryName;
ex.factory_tag = mTag;
throw ex;
}
try {
Process(event);
}
catch (JException& ex) {
std::string instanceName = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
if (ex.function_name.empty()) ex.function_name = "JFactory::Process";
if (ex.type_name.empty()) ex.type_name = mFactoryName;
if (ex.instance_name.empty()) ex.instance_name = instanceName;
if (ex.plugin_name.empty()) ex.plugin_name = mPluginName;
if (ex.component_name.empty()) ex.component_name = mFactoryName;
if (ex.factory_name.empty()) ex.factory_name = mFactoryName;
if (ex.factory_tag.empty()) ex.factory_tag = mTag;
throw ex;
}
catch (std::exception& e) {
auto ex = JException("Exception in JFactory::Process(): %s", e.what());
auto ex = JException(e.what());
ex.nested_exception = std::current_exception();
ex.function_name = "JFactory::Process";
ex.type_name = mFactoryName;
ex.instance_name = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
ex.plugin_name = mPluginName;
ex.component_name = mFactoryName;
ex.factory_name = mFactoryName;
ex.factory_tag = mTag;
throw ex;
}
catch (...) {
auto ex = JException("Unknown exception in JFactory::Process()");
auto ex = JException("Unknown exception");
ex.nested_exception = std::current_exception();
ex.function_name = "JFactory::Process";
ex.type_name = mFactoryName;
ex.instance_name = mTag.empty() ? mObjectName : mObjectName + ":" + mTag;
ex.plugin_name = mPluginName;
ex.component_name = mFactoryName;
ex.factory_name = mFactoryName;
ex.factory_tag = mTag;
throw ex;
}
mStatus = Status::Processed;
Expand Down
30 changes: 20 additions & 10 deletions src/libraries/JANA/JMultifactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ void JMultifactory::SetData(std::string tag, std::vector<T*> data) {
JFactoryT<T>* helper = mHelpers.GetFactory<T>(tag);
if (helper == nullptr) {
auto ex = JException("JMultifactory: Attempting to SetData() without corresponding DeclareOutput()");
ex.factory_name = m_type_name;
ex.factory_tag = m_prefix;
ex.function_name = "JMultifactory::SetData";
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
throw ex;
}
#ifdef JANA2_HAVE_PODIO
Expand Down Expand Up @@ -187,15 +189,19 @@ void JMultifactory::SetCollection(std::string tag, typename JFactoryPodioT<T>::C
JFactoryT<T>* helper = mHelpers.GetFactory<T>(tag);
if (helper == nullptr) {
auto ex = JException("JMultifactory: Attempting to SetData() without corresponding DeclareOutput()");
ex.factory_name = m_type_name;
ex.factory_tag = m_prefix;
ex.function_name = "JMultifactory::SetCollection";
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
throw ex;
}
auto* typed = dynamic_cast<JFactoryPodioT<T>*>(helper);
if (typed == nullptr) {
auto ex = JException("JMultifactory: Helper needs to be a JFactoryPodioT (this shouldn't be reachable)");
ex.factory_name = m_type_name;
ex.factory_tag = m_prefix;
ex.function_name = "JMultifactory::SetCollection";
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
throw ex;
}

Expand All @@ -208,15 +214,19 @@ void JMultifactory::SetCollection(std::string tag, std::unique_ptr<typename JFac
JFactoryT<T>* helper = mHelpers.GetFactory<T>(tag);
if (helper == nullptr) {
auto ex = JException("JMultifactory: Attempting to SetData() without corresponding DeclareOutput()");
ex.factory_name = m_type_name;
ex.factory_tag = m_prefix;
ex.function_name = "JMultifactory::SetCollection";
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
throw ex;
}
auto* typed = dynamic_cast<JFactoryPodioT<T>*>(helper);
if (typed == nullptr) {
auto ex = JException("JMultifactory: Helper needs to be a JFactoryPodioT (this shouldn't be reachable)");
ex.factory_name = m_type_name;
ex.factory_tag = m_prefix;
ex.function_name = "JMultifactory::SetCollection";
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
throw ex;
}

Expand Down
15 changes: 9 additions & 6 deletions src/libraries/JANA/Omni/JComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,28 @@ inline void JComponent::CallWithJExceptionWrapper(std::string func_name, F func)
func();
}
catch (JException& ex) {
if (ex.function_name.empty()) ex.function_name = func_name;
if (ex.type_name.empty()) ex.type_name = m_type_name;
if (ex.instance_name.empty()) ex.instance_name = m_prefix;
if (ex.plugin_name.empty()) ex.plugin_name = m_plugin_name;
if (ex.component_name.empty()) ex.component_name = m_type_name;
if (ex.callback_name.empty()) ex.callback_name = func_name;
throw ex;
}
catch (std::exception& e) {
auto ex = JException(e.what());
ex.nested_exception = std::current_exception();
ex.callback_name = func_name;
ex.function_name = func_name;
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
ex.component_name = m_type_name;
throw ex;
}
catch (...) {
auto ex = JException("Unknown exception");
ex.nested_exception = std::current_exception();
ex.callback_name = func_name;
ex.function_name = func_name;
ex.type_name = m_type_name;
ex.instance_name = m_prefix;
ex.plugin_name = m_plugin_name;
ex.component_name = m_type_name;
throw ex;
}
}
Expand Down

0 comments on commit 808fd9d

Please sign in to comment.