summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-11 10:07:15 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-11 10:07:15 +0100
commit52c4dc49cf460dad4edc42457ba9e3ca4c7674d5 (patch)
tree6d5d123756c8d79ab5add4660e7b66beb3e89736 /lib/book.js
parent44ad70320a0d0b907702c57e560c6a60373c9bca (diff)
downloadgitbook-52c4dc49cf460dad4edc42457ba9e3ca4c7674d5.zip
gitbook-52c4dc49cf460dad4edc42457ba9e3ca4c7674d5.tar.gz
gitbook-52c4dc49cf460dad4edc42457ba9e3ca4c7674d5.tar.bz2
Normalize errors
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/book.js b/lib/book.js
index fd20a94..def724b 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -11,6 +11,7 @@ var Summary = require('./backbone/summary');
var Langs = require('./backbone/langs');
var Page = require('./backbone/page');
var pathUtil = require('./utils/path');
+var error = require('./utils/error');
var Promise = require('./utils/promise');
@@ -40,7 +41,7 @@ function Book(opts) {
logLevel: 'info'
});
- if (!opts.fs) throw new Error('Book requires a fs instance');
+ if (!opts.fs) throw error.ParsingError(new Error('Book requires a fs instance'));
// Root path for the book
this.root = opts.root;
@@ -101,9 +102,10 @@ Book.prototype.prepareConfig = function() {
Book.prototype.resolve = function() {
var filename = path.resolve.apply(path, [this.root].concat(_.toArray(arguments)));
if (!this.isFileInScope(filename)) {
- var err = new Error('EACCESS: "' + filename + '" not in "' + this.root + '"');
- err.code = 'EACCESS';
- throw err;
+ throw error.FileOutOfScopeError({
+ filename: filename,
+ root: this.root
+ });
}
return filename;
@@ -154,7 +156,7 @@ Book.prototype.parse = function() {
.then(function() {
if (that.isMultilingual()) {
if (that.isLanguageBook()) {
- throw new Error('A multilingual book as a language book is forbidden');
+ throw error.ParsingError(new Error('A multilingual book as a language book is forbidden'));
}
that.log.info.ln('Parsing multilingual book, with', that.langs.count(), 'languages');
@@ -180,14 +182,14 @@ Book.prototype.parse = function() {
.then(function() {
if (that.readme.exists()) return;
- throw new Error('No README file (or is ignored)');
+ throw new error.FileNotFoundError({ filename: 'README' });
})
// Parse the summary
.then(that.summary.load)
.then(function() {
if (!that.summary.exists()) {
- throw new Error('No SUMMARY file (or is ignored)');
+ throw new error.FileNotFoundError({ filename: 'SUMMARY' });
}
// Index summary's articles
@@ -229,7 +231,7 @@ Book.prototype.isFileIgnored = function(filename) {
// Read a file in the book, throw error if ignored
Book.prototype.readFile = function(filename) {
- if (this.isFileIgnored(filename)) return Promise.reject(new Error('File "'+filename+'" is ignored'));
+ if (this.isFileIgnored(filename)) return Promise.reject(new error.FileNotFoundError({ filename: filename }));
return this.fs.readAsString(this.resolve(filename));
};