diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-25 15:09:57 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-25 15:09:57 +0100 |
commit | 393aed62706745e2abde300844143b5d2a0c9041 (patch) | |
tree | 33da1c4e18796ccfe1ad3638228a1fde953e668c /lib/utils | |
parent | b240d6a8fcbab80ea35da8cee58576f674ea1821 (diff) | |
download | gitbook-393aed62706745e2abde300844143b5d2a0c9041.zip gitbook-393aed62706745e2abde300844143b5d2a0c9041.tar.gz gitbook-393aed62706745e2abde300844143b5d2a0c9041.tar.bz2 |
Improve error msg for ebook generation
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/command.js | 21 | ||||
-rw-r--r-- | lib/utils/error.js | 20 | ||||
-rw-r--r-- | lib/utils/images.js | 7 |
3 files changed, 45 insertions, 3 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js index 49b0998..c1689cb 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -11,7 +11,26 @@ function exec(command, options) { return Promise.reject(new Error('Command execution is not possible on this platform')); } - return Promise.nfcall(childProcess.exec, command, options); + var d = Promise.defer(); + + var child = childProcess.exec(command, options, function(err, stdout, stderr) { + if (!err) { + d.resolve(); + } + + err.message = stdout.toString('utf8') + stderr.toString('utf8'); + d.reject(err); + }); + + child.stdout.on('data', function (data) { + d.notify(data); + }); + + child.stderr.on('data', function (data) { + d.notify(data); + }); + + return d.promise; } // Spawn an executable diff --git a/lib/utils/error.js b/lib/utils/error.js index 52281bf..27fa59d 100644 --- a/lib/utils/error.js +++ b/lib/utils/error.js @@ -41,6 +41,15 @@ var FileOutOfScopeError = TypedError({ code: 'EACCESS' }); +// A file is outside the scope +var RequireInstallError = TypedError({ + type: 'install.required', + message: '"{cmd}" is not installed.\n{install}', + cmd: null, + code: 'ENOENT', + install: '' +}); + // Error for nunjucks templates var TemplateError = WrappedError({ message: 'Error compiling template "{filename}": {origMessage}', @@ -55,12 +64,19 @@ var PluginError = WrappedError({ plugin: null }); -// Error for nunjucks templates +// Error with the book's configuration var ConfigurationError = WrappedError({ message: 'Error with book\'s configuration: {origMessage}', type: 'configuration' }); +// Error during ebook generation +var EbookError = WrappedError({ + message: 'Error during ebook generation: {origMessage}\n{stdout}', + type: 'ebook', + stdout: '' +}); + // Deprecate methods/fields function deprecateMethod(fn, msg) { return deprecated.method(msg, log.warn.ln, fn); @@ -74,6 +90,7 @@ module.exports = { ParsingError: ParsingError, OutputError: OutputError, + RequireInstallError: RequireInstallError, FileNotFoundError: FileNotFoundError, FileOutOfScopeError: FileOutOfScopeError, @@ -81,6 +98,7 @@ module.exports = { TemplateError: TemplateError, PluginError: PluginError, ConfigurationError: ConfigurationError, + EbookError: EbookError, deprecateMethod: deprecateMethod, deprecateField: deprecateField diff --git a/lib/utils/images.js b/lib/utils/images.js index 8169b06..44356a1 100644 --- a/lib/utils/images.js +++ b/lib/utils/images.js @@ -10,7 +10,12 @@ function convertSVGToPNG(source, dest, options) { return command.spawn('svgexport', [source, dest]) .fail(function(err) { - if (err.code == 'ENOENT') err = new Error('Need to install "svgexport" using "npm install svgexport -g"'); + if (err.code == 'ENOENT') { + error.RequireInstallError({ + cmd: 'svgexport', + install: 'Install it using: "npm install svgexport -g"' + }); + } throw err; }) .then(function() { |