Skip to content

Commit

Permalink
Fabric: Catching exceptions in UIManager::completeRoot earlier, in C++
Browse files Browse the repository at this point in the history
Summary:
Fabric Core does not support exception safety, so technically exceptions are unrecoverable and binaries should be built without exception support.
While it's not the case, some exceptions might bubble to JavaScript realm and be caught as JavaScript exceptions. In this case, we lose the stack trace. To prevent that and to investigate one particular error we have we add this try-catch block in this diff.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D23529233

fbshipit-source-id: 7ac7fb26ac08ad26af8790172de471ac178c3a37
  • Loading branch information
shergin authored and facebook-github-bot committed Sep 5, 2020
1 parent 49015b0 commit 902611f
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,28 @@ jsi::Value UIManagerBinding::get(
jsi::Value const &thisValue,
jsi::Value const *arguments,
size_t count) -> jsi::Value {
auto surfaceId = surfaceIdFromValue(runtime, arguments[0]);
auto shadowNodeList =
shadowNodeListFromValue(runtime, arguments[1]);

if (sharedUIManager->backgroundExecutor_) {
sharedUIManager->backgroundExecutor_(
[sharedUIManager, surfaceId, shadowNodeList] {
sharedUIManager->completeSurface(surfaceId, shadowNodeList);
});
} else {
uiManager->completeSurface(surfaceId, shadowNodeList);
try {
auto surfaceId = surfaceIdFromValue(runtime, arguments[0]);
auto shadowNodeList =
shadowNodeListFromValue(runtime, arguments[1]);

if (sharedUIManager->backgroundExecutor_) {
sharedUIManager->backgroundExecutor_(
[sharedUIManager, surfaceId, shadowNodeList] {
sharedUIManager->completeSurface(
surfaceId, shadowNodeList);
});
} else {
uiManager->completeSurface(surfaceId, shadowNodeList);
}
} catch (std::exception const &e) {
LOG(ERROR) << "Exception in UIManagerBinding::completeRoot(): "
<< e.what();
abort();
} catch (...) {
LOG(ERROR)
<< "Exception in UIManagerBinding::completeRoot(): Unknown.";
abort();
}

return jsi::Value::undefined();
Expand All @@ -452,9 +463,19 @@ jsi::Value UIManagerBinding::get(
jsi::Value const &thisValue,
jsi::Value const *arguments,
size_t count) -> jsi::Value {
uiManager->completeSurface(
surfaceIdFromValue(runtime, arguments[0]),
shadowNodeListFromValue(runtime, arguments[1]));
try {
uiManager->completeSurface(
surfaceIdFromValue(runtime, arguments[0]),
shadowNodeListFromValue(runtime, arguments[1]));
} catch (std::exception const &e) {
LOG(ERROR) << "Exception in UIManagerBinding::completeRoot(): "
<< e.what();
abort();
} catch (...) {
LOG(ERROR)
<< "Exception in UIManagerBinding::completeRoot(): Unknown.";
abort();
}

return jsi::Value::undefined();
});
Expand Down

0 comments on commit 902611f

Please sign in to comment.