Change performAndReportError to handle exception pointers

Summary: Since plugins aren't under our control, they might throw exception pointers. We can still extract the useful info in this case.

Reviewed By: passy

Differential Revision: D14244362

fbshipit-source-id: 5f18100c08160e7514b3fd88ec47809cb37e9770
This commit is contained in:
John Knox
2019-02-28 05:36:24 -08:00
committed by Facebook Github Bot
parent e594176401
commit 85c041ff8d
2 changed files with 18 additions and 9 deletions

View File

@@ -302,15 +302,10 @@ void FlipperClient::performAndReportError(const std::function<void()>& func) {
try { try {
func(); func();
} catch (std::exception& e) { } catch (std::exception& e) {
if (connected_) { handleError(e);
std::string callstack = this->callstack(); } catch (std::exception* e) {
dynamic message = dynamic::object( if (e) {
"error", handleError(*e);
dynamic::object("message", e.what())("stacktrace", callstack)(
"name", e.what()));
socket_->sendMessage(message);
} else {
log("Error: " + std::string(e.what()));
} }
} catch (...) { } catch (...) {
// Generic catch block for the exception of type not belonging to // Generic catch block for the exception of type not belonging to
@@ -320,6 +315,19 @@ void FlipperClient::performAndReportError(const std::function<void()>& func) {
#endif #endif
} }
void FlipperClient::handleError(std::exception& e) {
if (connected_) {
std::string callstack = this->callstack();
dynamic message = dynamic::object(
"error",
dynamic::object("message", e.what())("stacktrace", callstack)(
"name", e.what()));
socket_->sendMessage(message);
} else {
log("Error: " + std::string(e.what()));
}
}
std::string FlipperClient::getState() { std::string FlipperClient::getState() {
return flipperState_->getState(); return flipperState_->getState();
} }

View File

@@ -110,6 +110,7 @@ class FlipperClient : public FlipperConnectionManager::Callbacks {
void disconnect(std::shared_ptr<FlipperPlugin> plugin); void disconnect(std::shared_ptr<FlipperPlugin> plugin);
void startBackgroundPlugins(); void startBackgroundPlugins();
std::string callstack(); std::string callstack();
void handleError(std::exception& e);
}; };
} // namespace flipper } // namespace flipper