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,6 +302,20 @@ void FlipperClient::performAndReportError(const std::function<void()>& func) {
try {
func();
} catch (std::exception& e) {
handleError(e);
} catch (std::exception* e) {
if (e) {
handleError(*e);
}
} catch (...) {
// Generic catch block for the exception of type not belonging to
// std::exception
log("Unknown error suppressed in FlipperClient");
}
#endif
}
void FlipperClient::handleError(std::exception& e) {
if (connected_) {
std::string callstack = this->callstack();
dynamic message = dynamic::object(
@@ -312,12 +326,6 @@ void FlipperClient::performAndReportError(const std::function<void()>& func) {
} else {
log("Error: " + std::string(e.what()));
}
} catch (...) {
// Generic catch block for the exception of type not belonging to
// std::exception
log("Unknown error suppressed in FlipperClient");
}
#endif
}
std::string FlipperClient::getState() {

View File

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