From 95bcc21a066d0849b0b5399a8d7825b01d6390aa Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 29 Nov 2016 15:54:10 -0800 Subject: Add useful nodeify error message If a nodified method does not return a Promise, it will throw an error, like this: ``` Error in event handler for (unknown): Error: The function setSelectedAccount did not return a Promise, but was nodeified. ``` --- app/scripts/lib/nodeify.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/nodeify.js') diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js index 56b793852..51d89a8fb 100644 --- a/app/scripts/lib/nodeify.js +++ b/app/scripts/lib/nodeify.js @@ -6,12 +6,19 @@ module.exports = function (promiseFn) { } var cb = arguments[arguments.length - 1] - return promiseFn.apply(this, args) - .then(function (result) { + const nodeified = promiseFn.apply(this, args) + + if (!nodeified) { + const methodName = String(promiseFn).split('(')[0] + throw new Error(`The ${methodName} did not return a Promise, but was nodeified.`) + } + nodeified.then(function (result) { cb(null, result) }) .catch(function (reason) { cb(reason) }) + + return nodeified } } -- cgit