From 1c19ae48bd8ede4626cab81430650573c87db501 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Feb 2014 20:39:27 -0500 Subject: [PATCH] fixed #1143 -- also removed near-meaningless info messages saying that a Hook had been registered. --- src/plugins.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index 9462785054..f334d8b0da 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -246,24 +246,31 @@ var fs = require('fs'), `data.priority`, the relative priority of the method when it is eventually called (default: 10) */ + var method; + if (data.hook && data.method && typeof data.method === 'string' && data.method.length > 0) { data.id = id; if (!data.priority) data.priority = 10; - data.method = data.method.split('.').reduce(function(memo, prop) { - if (memo[prop]) { + method = data.method.split('.').reduce(function(memo, prop) { + if (memo !== null && memo[prop]) { return memo[prop]; } else { - // Couldn't find method by path, assuming property with periods in it (evil!) - Plugins.libraries[data.id][data.method]; + // Couldn't find method by path, aborting + return null; } }, Plugins.libraries[data.id]); + if (method === null) { + winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method); + return callback(); + } + + // Write the actual method reference to the hookObj + data.method = method; + Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || []; Plugins.loadedHooks[data.hook].push(data); - if (global.env === 'development') { - winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id); - } callback(); } else return; };