Skip to content

Commit d9d81a7

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Terminate on logic error in createNode HostFunction (facebook#41567)
Summary: Pull Request resolved: facebook#41567 Sometimes `createNode` calls into is throwing `std::out_of_range_error` or `std::length_error` in response to both vector and string operations. Instead of propagating `std::logic_error`, which indicates a defect in native code, terminate, so we can get an actionable native stack trace. `createNode` and `cloneNode` also both ocasionally see `bad_alloc`, but this is not usually an instance of a defect at the allocation-site, and throwing would be more graceful. Changelog: [Internal] Reviewed By: javache Differential Revision: D51463600 fbshipit-source-id: 870cbf3538d8ccbc01ded2868781a63ba12a941c
1 parent 99d407d commit d9d81a7

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,27 @@ jsi::Value UIManagerBinding::get(
230230
const jsi::Value& /*thisValue*/,
231231
const jsi::Value* arguments,
232232
size_t count) -> jsi::Value {
233-
validateArgumentCount(runtime, methodName, paramCount, count);
234-
235-
auto instanceHandle =
236-
instanceHandleFromValue(runtime, arguments[4], arguments[0]);
237-
if (!instanceHandle) {
238-
react_native_assert(false);
239-
return jsi::Value::undefined();
233+
try {
234+
validateArgumentCount(runtime, methodName, paramCount, count);
235+
236+
auto instanceHandle =
237+
instanceHandleFromValue(runtime, arguments[4], arguments[0]);
238+
if (!instanceHandle) {
239+
react_native_assert(false);
240+
return jsi::Value::undefined();
241+
}
242+
243+
return valueFromShadowNode(
244+
runtime,
245+
uiManager->createNode(
246+
tagFromValue(arguments[0]),
247+
stringFromValue(runtime, arguments[1]),
248+
surfaceIdFromValue(runtime, arguments[2]),
249+
RawProps(runtime, arguments[3]),
250+
std::move(instanceHandle)));
251+
} catch (const std::logic_error& ex) {
252+
LOG(FATAL) << "logic_error in createNode: " << ex.what();
240253
}
241-
242-
return valueFromShadowNode(
243-
runtime,
244-
uiManager->createNode(
245-
tagFromValue(arguments[0]),
246-
stringFromValue(runtime, arguments[1]),
247-
surfaceIdFromValue(runtime, arguments[2]),
248-
RawProps(runtime, arguments[3]),
249-
std::move(instanceHandle)));
250254
});
251255
}
252256

0 commit comments

Comments
 (0)