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
@@ -56,7 +56,13 @@ type Examples =
|
||||
| 'rejectPromise'
|
||||
| 'voidFunc'
|
||||
| 'optionalArgs'
|
||||
| 'emitDeviceEvent';
|
||||
| 'emitDeviceEvent'
|
||||
| 'voidFuncThrows'
|
||||
| 'getObjectThrows'
|
||||
| 'promiseThrows'
|
||||
| 'voidFuncAssert'
|
||||
| 'getObjectAssert'
|
||||
| 'promiseAssert';
|
||||
|
||||
class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
static contextType: React$Context<RootTag> = RootTagContext;
|
||||
@@ -112,6 +118,50 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
});
|
||||
NativeCxxModuleExample?.emitCustomDeviceEvent(CUSTOM_EVENT_TYPE);
|
||||
},
|
||||
voidFuncThrows: () => {
|
||||
try {
|
||||
NativeCxxModuleExample?.voidFuncThrows();
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
getObjectThrows: () => {
|
||||
try {
|
||||
NativeCxxModuleExample?.getObjectThrows({a: 1, b: 'foo', c: null});
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
promiseThrows: () => {
|
||||
try {
|
||||
// $FlowFixMe[unused-promise]
|
||||
NativeCxxModuleExample?.promiseThrows();
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
voidFuncAssert: () => {
|
||||
try {
|
||||
NativeCxxModuleExample?.voidFuncAssert();
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
getObjectAssert: () => {
|
||||
try {
|
||||
NativeCxxModuleExample?.getObjectAssert({a: 1, b: 'foo', c: null});
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
promiseAssert: () => {
|
||||
try {
|
||||
// $FlowFixMe[unused-promise]
|
||||
NativeCxxModuleExample?.promiseAssert();
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
_setResult(
|
||||
@@ -155,9 +205,6 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
|
||||
'Cannot load this example because TurboModule is not configured.',
|
||||
);
|
||||
}
|
||||
Object.keys(this._tests).forEach(item =>
|
||||
this._setResult(item, this._tests[item]()),
|
||||
);
|
||||
}
|
||||
|
||||
render(): React.Node {
|
||||
|
||||
Reference in New Issue
Block a user