summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 15:53:37 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 15:53:37 +0100
commitb2af55ac63886cba2075043554ff78c787cbb9e1 (patch)
tree18272b8172e12b38e6b84d890775913e541627d1 /lib/plugins
parent40cdc285b613949347f2909d8f7027fc51b0db7f (diff)
downloadgitbook-b2af55ac63886cba2075043554ff78c787cbb9e1.zip
gitbook-b2af55ac63886cba2075043554ff78c787cbb9e1.tar.gz
gitbook-b2af55ac63886cba2075043554ff78c787cbb9e1.tar.bz2
Wrap error when loading plugin
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/plugin.js14
1 files changed, 11 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;
})