Tweaks to plugin load error detection

This commit is contained in:
Nick Farina
2015-11-11 15:16:29 -08:00
parent 2d73e70670
commit ec839b2dbc

View File

@@ -37,11 +37,6 @@ Plugin.prototype.load = function(options) {
// attempt to load package.json // attempt to load package.json
var pjson = Plugin.loadPackageJSON(this.pluginPath); var pjson = Plugin.loadPackageJSON(this.pluginPath);
// make sure the name is prefixed with 'homebridge-'
if (!pjson.name || pjson.name.indexOf('homebridge-') != 0) {
throw new Error("Plugin " + this.pluginPath + " does not have a package name that begins with 'homebridge-'.");
}
// very temporary fix for first wave of plugins // very temporary fix for first wave of plugins
if (pjson.peerDepdendencies && (!pjson.engines || !pjson.engines.homebridge)) { if (pjson.peerDepdendencies && (!pjson.engines || !pjson.engines.homebridge)) {
var engines = pjson.engines || {} var engines = pjson.engines || {}
@@ -87,6 +82,11 @@ Plugin.loadPackageJSON = function(pluginPath) {
throw new Error("Plugin " + pluginPath + " contains an invalid package.json. Error: " + err); throw new Error("Plugin " + pluginPath + " contains an invalid package.json. Error: " + err);
} }
// make sure the name is prefixed with 'homebridge-'
if (!pjson.name || pjson.name.indexOf('homebridge-') != 0) {
throw new Error("Plugin " + pluginPath + " does not have a package name that begins with 'homebridge-'.");
}
// verify that it's tagged with the correct keyword // verify that it's tagged with the correct keyword
if (!pjson.keywords || pjson.keywords.indexOf("homebridge-plugin") == -1) { if (!pjson.keywords || pjson.keywords.indexOf("homebridge-plugin") == -1) {
throw new Error("Plugin " + pluginPath + " package.json does not contain the keyword 'homebridge-plugin'."); throw new Error("Plugin " + pluginPath + " package.json does not contain the keyword 'homebridge-plugin'.");
@@ -176,11 +176,12 @@ Plugin.installed = function() {
pjson = Plugin.loadPackageJSON(pluginPath); pjson = Plugin.loadPackageJSON(pluginPath);
} }
catch (err) { catch (err) {
if (name.substring(0,11) === 'homebridge-') { // is this "trying" to be a homebridge plugin? if so let you know what went wrong.
// show warning only if module starts with prefix if (!name || name.indexOf('homebridge-') == 0) {
log.warn("Warning: skipping plugin found at '" + pluginPath + "' because of: " + err.message); log.warn(err.message);
} }
// swallow error and skip this module
// skip this module
continue; continue;
} }