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