summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-25 15:09:57 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-25 15:09:57 +0100
commit393aed62706745e2abde300844143b5d2a0c9041 (patch)
tree33da1c4e18796ccfe1ad3638228a1fde953e668c
parentb240d6a8fcbab80ea35da8cee58576f674ea1821 (diff)
downloadgitbook-393aed62706745e2abde300844143b5d2a0c9041.zip
gitbook-393aed62706745e2abde300844143b5d2a0c9041.tar.gz
gitbook-393aed62706745e2abde300844143b5d2a0c9041.tar.bz2
Improve error msg for ebook generation
-rw-r--r--lib/output/ebook.js11
-rw-r--r--lib/utils/command.js21
-rw-r--r--lib/utils/error.js20
-rw-r--r--lib/utils/images.js7
4 files changed, 54 insertions, 5 deletions
diff --git a/lib/output/ebook.js b/lib/output/ebook.js
index 0cd1807..a74af41 100644
--- a/lib/output/ebook.js
+++ b/lib/output/ebook.js
@@ -5,6 +5,7 @@ var juice = require('juice');
var command = require('../utils/command');
var fs = require('../utils/fs');
var Promise = require('../utils/promise');
+var error = require('../utils/error');
var WebsiteOutput = require('./website');
var assetsInliner = require('./assets-inliner');
@@ -59,12 +60,18 @@ EbookOutput.prototype.finish = function() {
].join(' ');
return command.exec(cmd)
+ .progress(function(data) {
+ that.book.log.debug(data);
+ })
.fail(function(err) {
if (err.code == 127) {
- err = new Error('Need to install ebook-convert from Calibre');
+ throw error.RequireInstallError({
+ cmd: 'ebook-convert',
+ install: 'Install it from Calibre: https://calibre-ebook.com'
+ });
}
- throw err;
+ throw error.EbookError(err);
});
});
};
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() {