Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages for ReactPackage missing empty list implementation #18107

Closed

Conversation

Nkzn
Copy link

@Nkzn Nkzn commented Feb 26, 2018

Motivation

When we create custom ReactPackage for Native Modules or Native UI Components, we often forget to add Collections.emptyList() and produce NullPointerException repeatedly. This error log remind us to add empty code.

And also, the NPE message from this probrem is ambiguous. This fix is useful for RN beginners.

Test Plan

This test can do in the RNTester manually.

Test ReactInstanceManager

To show error log in ReactInstanceManager, add ReactPackage into RNTesterApplication like below.

@Override
public List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new ReactPackage() {
        @Override
        public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        return Collections.emptyList();
        }

        @Override
        public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return null;
        }
    }
  );
}

And run RNTester as Android App, the error log will show in LogCat. (with app crashes)

Test NativeModuleRegistryBuilder

Same as test for NativeModuleRegistryBuilder, write like below.

@Override
public List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new ReactPackage() {
        @Override
        public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        return null;
        }

        @Override
        public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();
        }
    }
  );
}

And run RNTester as Android App, the error log will show in LogCat. (without app crashes)

Release Notes

[ANDROID] [ENHANCEMENT] [ReactPackage] - Add error log for ReactPackage missing empty list implementation

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. cla signed labels Feb 26, 2018
@Nkzn
Copy link
Author

Nkzn commented Feb 26, 2018

Bad Credentials? 😕 > ci/circleci: analyze_pr

@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch 2 times, most recently from 019599a to be9bb32 Compare February 28, 2018 00:50
@Nkzn
Copy link
Author

Nkzn commented Feb 28, 2018

Why tvos ci fails... I edited only android....

@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from be9bb32 to d401179 Compare February 28, 2018 01:17
@sdwilsh sdwilsh removed the cla signed label Mar 1, 2018
@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from d401179 to 697d3fd Compare March 6, 2018 12:54
@hramos hramos added Android and removed Android labels Mar 13, 2018
@react-native-bot react-native-bot added Feature Request 🌟 Ran Commands One of our bots successfully processed a command. labels Mar 16, 2018
@hramos hramos added Type: Enhancement A new feature or enhancement of an existing feature. and removed 🌟Feature Request labels Mar 19, 2018
@facebook-github-bot
Copy link
Contributor

@Nkzn I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from 697d3fd to 48370c1 Compare April 10, 2018 11:45
@Nkzn
Copy link
Author

Nkzn commented Apr 10, 2018

thanks bot! I rebased.

@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from 48370c1 to e1b0da4 Compare April 19, 2018 08:08
@Nkzn
Copy link
Author

Nkzn commented Apr 19, 2018

why ci fail...? i rebased again.

@facebook-github-bot
Copy link
Contributor

@Nkzn I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from e1b0da4 to 742fb9a Compare May 20, 2018 02:37
@Nkzn Nkzn changed the title Add error log for ReactPackage missing empty list implementation Better error messages for ReactPackage missing empty list implementation Jun 19, 2018
@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from 742fb9a to ab6763b Compare June 19, 2018 02:04
@facebook-github-bot
Copy link
Contributor

@Nkzn I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@Nkzn Nkzn force-pushed the notice-reactpackage-emptylist-missing branch from ab6763b to e8fa6a5 Compare July 30, 2018 02:42
@facebook-github-bot
Copy link
Contributor

@Nkzn I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@@ -88,6 +90,12 @@ public void processPackage(ReactPackage reactPackage) {
} else {
nativeModules = reactPackage.createNativeModules(mReactApplicationContext);
}
if (nativeModules == null) {
Log.e(ReactConstants.TAG,
"ReactPackage#createNativeModules returns null. " +
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use reactPage.getClass().getSimpleName() to make it easy to identify which package got it wrong.

@cpojer
Copy link
Contributor

cpojer commented Jan 29, 2019

Thank you for this Pull Request. This is definitely useful. We are currently evaluating how to standardize and make it easier to create native modules and will make sure that error handling works better, see react-native-community/discussions-and-proposals#96. Unfortunately the code here is outdated (I'm sorry we didn't get to it earlier) so I have to close the PR :(

@cpojer cpojer closed this Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Ran Commands One of our bots successfully processed a command. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants