diff options
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 18 |
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)); }; |