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

Fix issue #6300: Improve error message for unregistered callbacks. #6436

Conversation

agiron123
Copy link
Contributor

Fix for issue #6300:
Motivation: When more than one callback is registered to a native module, the error message that a user receives is not indicative of what is really happening.

Test Plan:
MessageQueue. __invokeCallback(cbID, args) will need tests added.

Will need to add appropriate mocks for this._remoteMethodTable to return null and undefined.

Will need to test the cases when debug && this._remoteMethodTable[debug[0]][debug[1]];
returns null, undefined, and a non-null value.

Finally, will need to ensure that invariant(callback, errorMessage) function is called with the appropriate parameters.

As of right now, the code does not have unit tests attached. I can add them later if needed.

Demonstrate the code is solid:
To fix this issue, I first reproduced the conditions of the following issue:
#6286

To do so, I used the Movies sample project.
After successfully reproducing the error, I then followed the stack trace to come to the appropriate fix.
I can post the code to reproduce the issue if needed. It is essentially the same as that of issue #6286.

Let me know if you have any questions or concerns.

Commit Message:
Fix for issue #6300.
This fix adds a more descriptive error message for the error case when
more than one callback is registered to a native function.

Fix for issue facebook#6300.
This fix adds a more descriptive error message for the error case when
more than one callback is registered to a native function.
@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @tadeuzagallo, @davidaurelio and @nicklockwood to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@@ -192,9 +192,14 @@ class MessageQueue {
let debug = this._debugInfo[cbID >> 1];
let module = debug && this._remoteModuleTable[debug[0]];
let method = debug && this._remoteMethodTable[debug[0]][debug[1]];
let errorMessage = `Callback with id ${cbID}: ${module}.${method}() not found`;
if (method != null || method != undefined) {

Choose a reason for hiding this comment

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

eqeqeq: Expected '!==' and instead saw '!='.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 13, 2016
@facebook-github-bot
Copy link
Contributor

@agiron123 updated the pull request.

invariant(
callback,
`Callback with id ${cbID}: ${module}.${method}() not found`
errorMessage
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this whole thing (L192-L203) inside an if (!callback)? We can save all the array accesses + string concatenation in the common case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to code. I was able to surround everything with the if(!callback) statement except for the module and method variable declaration lines, as they are used both in the if statement and after the if statement. I really like this change. Nice and clean.

@facebook-github-bot
Copy link
Contributor

@agiron123 updated the pull request.

…ron123/react-native into unregisteredCallbackErrorImprovement
@facebook-github-bot
Copy link
Contributor

@agiron123 updated the pull request.

@agiron123
Copy link
Contributor Author

@tadeuzagallo Any more feedback?

@tadeuzagallo
Copy link
Contributor

@agiron123 No, that looks good, sorry for the delay.

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in fd2cf11 Mar 23, 2016
zebulgar pushed a commit to nightingale/react-native that referenced this pull request Jun 18, 2016
…acks.

Summary:Fix for issue facebook#6300:
Motivation: When more than one callback is registered to a native module, the error message that a user receives is not indicative of what is really happening.
Closes facebook#6436

Differential Revision: D3087551

Pulled By: tadeuzagallo

fb-gh-sync-id: 93c703348dc53b75c5b507edc71754680ab5c438
shipit-source-id: 93c703348dc53b75c5b507edc71754680ab5c438
This pull request was closed.
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants