mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Tweaks to plugin load error detection
This commit is contained in:
@@ -36,12 +36,7 @@ Plugin.prototype.load = function(options) {
|
||||
|
||||
// attempt to load package.json
|
||||
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
|
||||
if (pjson.peerDepdendencies && (!pjson.engines || !pjson.engines.homebridge)) {
|
||||
var engines = pjson.engines || {}
|
||||
@@ -87,6 +82,11 @@ Plugin.loadPackageJSON = function(pluginPath) {
|
||||
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
|
||||
if (!pjson.keywords || pjson.keywords.indexOf("homebridge-plugin") == -1) {
|
||||
throw new Error("Plugin " + pluginPath + " package.json does not contain the keyword 'homebridge-plugin'.");
|
||||
@@ -153,7 +153,7 @@ Plugin.installed = function() {
|
||||
if (!fs.existsSync(requirePath))
|
||||
continue;
|
||||
|
||||
var names = fs.readdirSync(requirePath);
|
||||
var names = fs.readdirSync(requirePath);
|
||||
|
||||
// does this path point inside a single plugin and not a directory containing plugins?
|
||||
if (fs.existsSync(path.join(requirePath, "package.json")))
|
||||
@@ -176,11 +176,12 @@ Plugin.installed = function() {
|
||||
pjson = Plugin.loadPackageJSON(pluginPath);
|
||||
}
|
||||
catch (err) {
|
||||
if (name.substring(0,11) === 'homebridge-') {
|
||||
// show warning only if module starts with prefix
|
||||
log.warn("Warning: skipping plugin found at '" + pluginPath + "' because of: " + err.message);
|
||||
// is this "trying" to be a homebridge plugin? if so let you know what went wrong.
|
||||
if (!name || name.indexOf('homebridge-') == 0) {
|
||||
log.warn(err.message);
|
||||
}
|
||||
// swallow error and skip this module
|
||||
|
||||
// skip this module
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user