mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add error reporting examples to rn-tester turbo modules (#36729)
Summary: This PR is adding examples of Turbo Modules functions throwing runtime exceptions and asserts. This should make it easier to collaborate and develop the error reporting for a new architecture that is being discussed in the React Native New Architecture Working Group -> https://github.com/reactwg/react-native-new-architecture/discussions/122. I'm not sure what return type should be used for the JS function returning `Promise<void>` in Cxx, I used [`AsyncPromise<jsi::Value>`](https://github.com/facebook/react-native/pull/36729/files#diff-9cebc75f48fd35fd6fef71138f98dfd0ba28a754b2aab0d6fe44fd685f74ce16R135), what would you use, I've not found `void` type to use? ### Added functions The table shows the current behavior. <table> <tr> <td> Function <td> Description <td> Turbo Module <td> Cxx Module <tr> <td> voidFuncThrows <td> function with return type void throws a runtime exception <td> platform error no JS stack trace <td> JS error no native stack trace <tr> <td> getObjectThrows <td> function with return type object throws a runtime exception <td> JS error no platform stack trace <td> JS error no native stack trace <tr> <td> promiseThrows <td> function with return type promise throws a runtime exception before settling the promise <td> platform error no JS stack trace <td> JS error no native stack trace <tr> <td> voidFuncAssert <td> function with return type void asserts <td> platform error no JS stack trace <td> native error no JS stack trace <tr> <td> getObjectAssert <td> function with return type object asserts <td> JS error no platform stack trace <td> native error no JS stack trace <tr> <td> promiseAssert <td> function with return type promise asserts before settling the promise <td> platform error no JS stack trace <td> native error no JS stack trace </table> ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [ADDED] - Error reporting examples in rn-tester turbo modules Pull Request resolved: https://github.com/facebook/react-native/pull/36729 Test Plan: This PR doesn't change any RN behavior. Only shows the current state by adding an example to rn-tester. I'm happy to add these examples to the unit/integration test, just point me to where would be a good place. Reviewed By: rshest Differential Revision: D44623027 Pulled By: javache fbshipit-source-id: d9cc04852b05d810ed11d7a94f1b2d455ef554a5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dc289737a8
commit
12a102b926
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "NativeCxxModuleExample.h"
|
||||
#include <react/debug/react_native_assert.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
@@ -142,4 +143,42 @@ void NativeCxxModuleExample::emitCustomDeviceEvent(
|
||||
});
|
||||
}
|
||||
|
||||
void NativeCxxModuleExample::voidFuncThrows(jsi::Runtime &rt) {
|
||||
throw std::runtime_error("Intentional exception from Cxx voidFuncThrows");
|
||||
};
|
||||
|
||||
ObjectStruct NativeCxxModuleExample::getObjectThrows(
|
||||
jsi::Runtime &rt,
|
||||
ObjectStruct arg) {
|
||||
throw std::runtime_error("Intentional exception from Cxx getObjectThrows");
|
||||
};
|
||||
|
||||
AsyncPromise<jsi::Value> NativeCxxModuleExample::promiseThrows(
|
||||
jsi::Runtime &rt) {
|
||||
throw std::runtime_error("Intentional exception from Cxx promiseThrows");
|
||||
};
|
||||
|
||||
void NativeCxxModuleExample::voidFuncAssert(jsi::Runtime &rt) {
|
||||
react_native_assert(false && "Intentional assert from Cxx voidFuncAssert");
|
||||
};
|
||||
|
||||
ObjectStruct NativeCxxModuleExample::getObjectAssert(
|
||||
jsi::Runtime &rt,
|
||||
ObjectStruct arg) {
|
||||
react_native_assert(false && "Intentional assert from Cxx getObjectAssert");
|
||||
|
||||
// Asserts disabled
|
||||
return {};
|
||||
};
|
||||
|
||||
AsyncPromise<jsi::Value> NativeCxxModuleExample::promiseAssert(
|
||||
jsi::Runtime &rt) {
|
||||
react_native_assert(false && "Intentional assert from Cxx promiseAssert");
|
||||
|
||||
// Asserts disabled
|
||||
auto promise = AsyncPromise<jsi::Value>(rt, jsInvoker_);
|
||||
promise.reject("Asserts disabled");
|
||||
return promise;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
Reference in New Issue
Block a user