plugins: improve error handling and introduce getDecoratedConfig

This commit is contained in:
Guillermo Rauch 2016-07-16 11:59:20 -07:00
parent 0ca6faf544
commit c2658ff1a0

View file

@ -233,7 +233,7 @@ function requirePlugins () {
mod = require(path); mod = require(path);
if (!mod || (!mod.onApp && !mod.onWindow && !mod.onUnload && if (!mod || (!mod.onApp && !mod.onWindow && !mod.onUnload &&
!mod.middleware && !mod.middleware && !mod.reduceUI && !mod.reduceSessions &&
!mod.decorateConfig && !mod.decorateMenu && !mod.decorateConfig && !mod.decorateMenu &&
!mod.decorateTerm && !mod.decorateHyperTerm && !mod.decorateTerm && !mod.decorateHyperTerm &&
!mod.decorateTab && !mod.decorateNotification && !mod.decorateTab && !mod.decorateNotification &&
@ -243,6 +243,10 @@ function requirePlugins () {
'HyperTerm extension API methods'); 'HyperTerm extension API methods');
return; return;
} }
// populate the name for internal errors here
mod._name = basename(path);
return mod; return mod;
} catch (err) { } catch (err) {
notify('Plugin error!', `Plugin "${basename(path)}" failed to load (${err.message})`); notify('Plugin error!', `Plugin "${basename(path)}" failed to load (${err.message})`);
@ -285,15 +289,15 @@ exports.decorateMenu = function (tpl) {
return decorated; return decorated;
}; };
exports.decorateConfig = function (config) { exports.getDecoratedConfig = function () {
let decorated = config; let decorated = config.getConfig();
modules.forEach((plugin) => { modules.forEach((plugin) => {
if (plugin.decorateConfig) { if (plugin.decorateConfig) {
const res = plugin.decorateConfig(decorated); const res = plugin.decorateConfig(decorated);
if (res) { if (res && 'object' === typeof res) {
decorated = res; decorated = res;
} else { } else {
console.error('incompatible response type for `decorateConfig`'); notify('Plugin error!', `"${plugin._name}": invalid return type for \`decorateConfig\``);
} }
} }
}); });