diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-17 15:53:37 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-17 15:53:37 +0100 |
commit | b2af55ac63886cba2075043554ff78c787cbb9e1 (patch) | |
tree | 18272b8172e12b38e6b84d890775913e541627d1 /lib | |
parent | 40cdc285b613949347f2909d8f7027fc51b0db7f (diff) | |
download | gitbook-b2af55ac63886cba2075043554ff78c787cbb9e1.zip gitbook-b2af55ac63886cba2075043554ff78c787cbb9e1.tar.gz gitbook-b2af55ac63886cba2075043554ff78c787cbb9e1.tar.bz2 |
Wrap error when loading plugin
Diffstat (limited to 'lib')
-rw-r--r-- | lib/plugins/plugin.js | 14 | ||||
-rw-r--r-- | lib/utils/error.js | 8 |
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 |