mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Read activePlugins from settings & improve error handling
issue #769 - activePlugins were being read from settings in two different ways, this has been simplified - error handling has been improved so that plugins do not crash Ghost - used full error messaging capabilities to make it easier to recover from errors
This commit is contained in:
parent
507174a00b
commit
6a0a453a96
@ -353,34 +353,33 @@ Ghost.prototype.doFilter = function (name, args) {
|
|||||||
|
|
||||||
// Initialise plugins. Will load from config.activePlugins by default
|
// Initialise plugins. Will load from config.activePlugins by default
|
||||||
Ghost.prototype.initPlugins = function (pluginsToLoad) {
|
Ghost.prototype.initPlugins = function (pluginsToLoad) {
|
||||||
pluginsToLoad = pluginsToLoad || JSON.parse(this.settings('activePlugins'));
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// If no activePlugins defined in config settings, look in database settings.
|
|
||||||
if (!_.isArray(pluginsToLoad)) {
|
if (!_.isArray(pluginsToLoad)) {
|
||||||
// The value will be resolved in the promise
|
|
||||||
pluginsToLoad = models.Settings.read("activePlugins").then(function (activePluginsSetting) {
|
|
||||||
var settingValue = activePluginsSetting.get('value') || '[]';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// We have to parse the value because it's a string
|
// We have to parse the value because it's a string
|
||||||
settingValue = JSON.parse(settingValue) || [];
|
pluginsToLoad = JSON.parse(this.settings('activePlugins')) || [];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return when.reject(new Error("Failed to parse activePlugins setting value: " + e.message));
|
errors.logError(
|
||||||
}
|
'Failed to parse activePlugins setting value: ' + e.message,
|
||||||
|
'Your plugins will not be loaded.',
|
||||||
// Resolve with the array value
|
'Check your settings table for typos in the activePlugins value. It should look like: ["plugin-1", "plugin2"] (double quotes required).'
|
||||||
return when.resolve(settingValue);
|
);
|
||||||
});
|
return when.resolve();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return when(pluginsToLoad).then(function (pluginsToLoadValue) {
|
return plugins.init(self, pluginsToLoad).then(function (loadedPlugins) {
|
||||||
return plugins.init(self, pluginsToLoad).then(function (loadedPlugins) {
|
// Extend the loadedPlugins onto the available plugins
|
||||||
// Extend the loadedPlugins onto the available plugins
|
_.extend(self.availablePlugins, loadedPlugins);
|
||||||
_.extend(self.availablePlugins, loadedPlugins);
|
}).otherwise(function (err) {
|
||||||
});
|
errors.logError(
|
||||||
}, errors.logAndThrowError);
|
err.message || err,
|
||||||
|
'The plugin will not be loaded',
|
||||||
|
'Check with the plugin creator, or read the plugin documentation for more details on plugin requirements'
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Ghost;
|
module.exports = Ghost;
|
||||||
|
@ -471,4 +471,4 @@ when(ghost.init()).then(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}, errors.logAndThrowError);
|
}).otherwise(errors.logAndThrowError);
|
||||||
|
Loading…
Reference in New Issue
Block a user