Skip to content
Snippets Groups Projects
Commit 4bb706bd authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'feature/#59' into 'main'

#59 Handler error reporting

See merge request beyondaka/beyond-protocol!39
parents e0de0566 9a2324ee
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <string>
#include <ftl/threads.hpp> #include <ftl/threads.hpp>
#include <ftl/exception.hpp> #include <ftl/exception.hpp>
...@@ -123,19 +124,21 @@ struct Handler : BaseHandler { ...@@ -123,19 +124,21 @@ struct Handler : BaseHandler {
*/ */
void trigger(ARGS ...args) { void trigger(ARGS ...args) {
bool hadFault = false; bool hadFault = false;
std::string faultMsg;
std::unique_lock<std::mutex> lk(mutex_); std::unique_lock<std::mutex> lk(mutex_);
for (auto i = callbacks_.begin(); i != callbacks_.end(); ) { for (auto i = callbacks_.begin(); i != callbacks_.end(); ) {
bool keep = true; bool keep = true;
try { try {
keep = i->second(args...); keep = i->second(args...);
} catch(...) { } catch(const std::exception &e) {
hadFault = true; hadFault = true;
faultMsg = e.what();
} }
if (!keep) i = callbacks_.erase(i); if (!keep) i = callbacks_.erase(i);
else else
++i; ++i;
} }
if (hadFault) throw FTL_Error("Callback exception"); if (hadFault) throw FTL_Error("Callback exception: " << faultMsg);
} }
/** /**
...@@ -146,20 +149,22 @@ struct Handler : BaseHandler { ...@@ -146,20 +149,22 @@ struct Handler : BaseHandler {
++jobs_; ++jobs_;
ftl::pool.push([this, args...](int id) { ftl::pool.push([this, args...](int id) {
bool hadFault = false; bool hadFault = false;
std::string faultMsg;
std::unique_lock<std::mutex> lk(mutex_); std::unique_lock<std::mutex> lk(mutex_);
for (auto i = callbacks_.begin(); i != callbacks_.end(); ) { for (auto i = callbacks_.begin(); i != callbacks_.end(); ) {
bool keep = true; bool keep = true;
try { try {
keep = i->second(args...); keep = i->second(args...);
} catch (...) { } catch(const std::exception &e) {
hadFault = true; hadFault = true;
faultMsg = e.what();
} }
if (!keep) i = callbacks_.erase(i); if (!keep) i = callbacks_.erase(i);
else else
++i; ++i;
} }
--jobs_; --jobs_;
if (hadFault) throw FTL_Error("Callback exception"); if (hadFault) throw FTL_Error("Callback exception: " << faultMsg);
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment