Skip to content

Commit

Permalink
Fix issue #6300: Improve error message for unregistered callbacks.
Browse files Browse the repository at this point in the history
Summary: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.
Closes #6436

Differential Revision: D3087551

Pulled By: tadeuzagallo

fb-gh-sync-id: 93c703348dc53b75c5b507edc71754680ab5c438
shipit-source-id: 93c703348dc53b75c5b507edc71754680ab5c438
  • Loading branch information
agiron123 authored and Facebook Github Bot 3 committed Mar 23, 2016
1 parent 85197a0 commit fd2cf11
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Libraries/Utilities/MessageQueue.js
Expand Up @@ -192,10 +192,17 @@ class MessageQueue {
let debug = this._debugInfo[cbID >> 1];
let module = debug && this._remoteModuleTable[debug[0]];
let method = debug && this._remoteMethodTable[debug[0]][debug[1]];
invariant(
callback,
`Callback with id ${cbID}: ${module}.${method}() not found`
);
if (!callback) {
let errorMessage = `Callback with id ${cbID}: ${module}.${method}() not found`;
if (method) {
errorMessage = `The callback ${method}() exists in module ${module}, `
+ `but only one callback may be registered to a function in a native module.`;
}
invariant(
callback,
errorMessage
);
}
let profileName = debug ? '<callback for ' + module + '.' + method + '>' : cbID;
if (callback && SPY_MODE && __DEV__) {
console.log('N->JS : ' + profileName + '(' + JSON.stringify(args) + ')');
Expand Down

0 comments on commit fd2cf11

Please sign in to comment.