From 4192790f05269181a1f50f31ce94e20c9a8ea2bf Mon Sep 17 00:00:00 2001 From: Sergei Dryganets Date: Thu, 12 Oct 2017 11:49:42 -0700 Subject: [PATCH] more detailed CxxModule logging Summary: Cxx module code swallows c++ exception details with sarcastic comment let native developer figure it out. Now instead of swallowing it, we print as much information as we can for different exception types. Still not ideal but way more informative. Have a crash in your c++ module and try to figure it out without this change. Closes https://github.com/facebook/react-native/pull/16193 Differential Revision: D6040038 Pulled By: javache fbshipit-source-id: 3fbe838383ca13395e21f74c9549474f6329cfeb --- ReactCommon/cxxreact/CxxNativeModule.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ReactCommon/cxxreact/CxxNativeModule.cpp b/ReactCommon/cxxreact/CxxNativeModule.cpp index f050ae1d2b3..a8e511fbec4 100644 --- a/ReactCommon/cxxreact/CxxNativeModule.cpp +++ b/ReactCommon/cxxreact/CxxNativeModule.cpp @@ -4,7 +4,7 @@ #include "Instance.h" #include - +#include #include #include "JsArgumentHelpers.h" @@ -12,7 +12,6 @@ #include "MessageQueueThread.h" using facebook::xplat::module::CxxModule; - namespace facebook { namespace react { @@ -140,9 +139,14 @@ void CxxNativeModule::invoke(unsigned int reactMethodId, folly::dynamic&& params method.func(std::move(params), first, second); } catch (const facebook::xplat::JsArgumentException& ex) { throw; + } catch (std::exception& e) { + LOG(ERROR) << "std::exception. Method call " << method.name.c_str() << " failed: " << e.what(); + std::terminate(); + } catch (std::string& error) { + LOG(ERROR) << "std::string. Method call " << method.name.c_str() << " failed: " << error.c_str(); + std::terminate(); } catch (...) { - // This means some C++ code is buggy. As above, we fail hard so the C++ - // developer can debug and fix it. + LOG(ERROR) << "Method call " << method.name.c_str() << " failed. unknown error"; std::terminate(); } });