From b55087dab7df8f0a00b2e98a80b62cc6b13c16a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 13 Dec 2017 12:06:45 -0500 Subject: [PATCH] closes #6166 --- src/plugins/hooks.js | 31 +++++++++++++++++-------------- test/plugins.js | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index 71b91beeef..020ea4e024 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -82,20 +82,23 @@ module.exports = function (Plugins) { var hookList = Plugins.loadedHooks[hook]; var hookType = hook.split(':')[0]; - - switch (hookType) { - case 'filter': - fireFilterHook(hook, hookList, params, callback); - break; - case 'action': - fireActionHook(hook, hookList, params, callback); - break; - case 'static': - fireStaticHook(hook, hookList, params, callback); - break; - default: - winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook); - break; + try { + switch (hookType) { + case 'filter': + fireFilterHook(hook, hookList, params, callback); + break; + case 'action': + fireActionHook(hook, hookList, params, callback); + break; + case 'static': + fireStaticHook(hook, hookList, params, callback); + break; + default: + winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook); + break; + } + } catch (err) { + callback(err); } }; diff --git a/test/plugins.js b/test/plugins.js index e948cbb160..dd6654cbef 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -70,6 +70,20 @@ describe('Plugins', function () { }); }); + it('should not crash if there is an exception in a hook', function (done) { + function filterMethod(data, callback) { + var crash; + crash.a = 5; + callback(null, data); + } + + + assert(err); + assert.equal(err.message, 'Cannot set property \'a\' of undefined'); + done(); + }); + }); + it('should get plugin data from nbbpm', function (done) { plugins.get('nodebb-plugin-markdown', function (err, data) { assert.ifError(err);