summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/plugins/plugin.js14
-rw-r--r--lib/utils/error.js8
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js
index 4ed619c..64ae75f 100644
--- a/lib/plugins/plugin.js
+++ b/lib/plugins/plugin.js
@@ -3,6 +3,7 @@ var path = require('path');
var resolve = require('resolve');
var Promise = require('../utils/promise');
+var error = require('../utils/error');
var gitbook = require('../gitbook');
var registry = require('./registry');
@@ -12,7 +13,7 @@ function BookPlugin(book, pluginId) {
this.id = pluginId;
this.npmId = registry.npmId(pluginId);
- this.baseDir;
+ this.root;
this.packageInfos = undefined;
this.content = undefined;
@@ -42,7 +43,7 @@ BookPlugin.prototype.load = function() {
try {
var res = resolve.sync(that.npmId + '/package.json', { basedir: baseDir });
- that.baseDir = path.dirname(res);
+ that.root = path.dirname(res);
that.packageInfos = require(res);
} catch (err) {
// Wait on https://github.com/substack/node-resolve/pull/81 to be merged
@@ -55,7 +56,14 @@ BookPlugin.prototype.load = function() {
}
// Load plugin JS content
- that.content = require(resolve.sync(that.npmId, { basedir: baseDir }));
+ try {
+ that.content = require(resolve.sync(that.npmId, { basedir: baseDir }));
+ } catch(err) {
+ throw new error.PluginError(err, {
+ plugin: that.id
+ });
+ }
+
return true;
})
diff --git a/lib/utils/error.js b/lib/utils/error.js
index c1abebd..53d8221 100644
--- a/lib/utils/error.js
+++ b/lib/utils/error.js
@@ -48,6 +48,13 @@ var TemplateError = WrappedError({
filename: null
});
+// Error for nunjucks templates
+var PluginError = WrappedError({
+ message: 'Error with plugin "{plugin}": {origMessage}',
+ type: 'plugin',
+ plugin: null
+});
+
// Deprecate methods/fields
function deprecateMethod(fn, msg) {
return deprecated.method(msg, log.warn.ln, fn);
@@ -66,6 +73,7 @@ module.exports = {
FileOutOfScopeError: FileOutOfScopeError,
TemplateError: TemplateError,
+ PluginError: PluginError,
deprecateMethod: deprecateMethod,
deprecateField: deprecateField