From e763c5cd15ff1f447c5ec7ef5dd45e843be2ef31 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 20 Sep 2018 03:45:33 -0700 Subject: [PATCH] Suppress crash due to Flipper Plugins Summary: This diff wraps the call to refresh plugins in `performAndReport`. All the important methods are already wrapped in this function. This diff also logs the error in the standard error if the connection is not established. With this diff the iOS app should not crash due exceptions thrown in iOS and cpp code. For android the app won't crash due to exception of cpp but can crash due to exceptions thrown in java code of the plugin Reviewed By: jknoxville Differential Revision: D9848112 fbshipit-source-id: 689ef9240e47400e8ce8c89b4c0ccec43d2180f9 --- xplat/Sonar/SonarClient.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/xplat/Sonar/SonarClient.cpp b/xplat/Sonar/SonarClient.cpp index 463bc7c75..63bf8dd5f 100644 --- a/xplat/Sonar/SonarClient.cpp +++ b/xplat/Sonar/SonarClient.cpp @@ -15,6 +15,9 @@ #include "ConnectionContextStore.h" #include "Log.h" #include +#include +#include +#include #if FB_SONARKIT_ENABLED @@ -99,8 +102,10 @@ void SonarClient::disconnect(std::shared_ptr plugin) { } void SonarClient::refreshPlugins() { - dynamic message = dynamic::object("method", "refreshPlugins"); - socket_->sendMessage(message); + performAndReportError([this]() { + dynamic message = dynamic::object("method", "refreshPlugins"); + socket_->sendMessage(message); + }); } void SonarClient::onConnected() { @@ -197,11 +202,13 @@ void SonarClient::performAndReportError(const std::function& func) { try { func(); } catch (std::exception& e) { - if (connected_) { dynamic message = dynamic::object( - "error", - dynamic::object("message", e.what())("stacktrace", "")); + "error", + dynamic::object("message", e.what())("stacktrace", "")); + if (connected_) { socket_->sendMessage(message); + } else { + log("SonarError : " + std::string(e.what())); } } }