From fd2cf119b13af65dbaeed9c5a6a34cfd27ef06af Mon Sep 17 00:00:00 2001 From: Andre Giron Date: Wed, 23 Mar 2016 10:07:45 -0700 Subject: [PATCH] Fix issue #6300: Improve error message for unregistered callbacks. 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 https://github.com/facebook/react-native/pull/6436 Differential Revision: D3087551 Pulled By: tadeuzagallo fb-gh-sync-id: 93c703348dc53b75c5b507edc71754680ab5c438 shipit-source-id: 93c703348dc53b75c5b507edc71754680ab5c438 --- Libraries/Utilities/MessageQueue.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Libraries/Utilities/MessageQueue.js b/Libraries/Utilities/MessageQueue.js index 2e542b6c4..e9df21105 100644 --- a/Libraries/Utilities/MessageQueue.js +++ b/Libraries/Utilities/MessageQueue.js @@ -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 ? '' : cbID; if (callback && SPY_MODE && __DEV__) { console.log('N->JS : ' + profileName + '(' + JSON.stringify(args) + ')');