diff options
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/lib/book.js b/lib/book.js index e357ad8..2f4aa7c 100644 --- a/lib/book.js +++ b/lib/book.js @@ -235,8 +235,15 @@ Book.prototype.generate = function(generator) { return _.reduce(ops["content"] || [], function(prev, file, i) { return prev.then(function() { var p = ((i*100)/nFiles).toFixed(0)+"%"; - that.log.info.ln("processing", file, p); - return Q(generator.convertFile(file)); + that.log.debug.ln("processing", file, p); + + return Q(generator.convertFile(file)) + .fail(function(err) { + // Transform error message to signal file + throw that.normError(err, { + fileName: file + }); + }); }); }, Q()); }); @@ -734,6 +741,32 @@ Book.prototype.i18n = function(phrase) { return i18n.__.apply({}, [this.config.normalizeLanguage()].concat(args)); }; +// Normalize error +Book.prototype.normError = function(err, opts) { + opts = _.defaults(opts || {}, { + + }); + + if (_.isString(err)) err = new Error(err); + + // Extend err + _.extend(err, opts); + + err.lineNumber = err.lineNumber || err.lineno; + err.columnNumber = err.columnNumber || err.colno; + + err.toString = function() { + var attributes = []; + + if (this.fileName) attributes.push("In file '"+this.fileName+"'"); + if (this.lineNumber) attributes.push("Line "+this.lineNumber); + if (this.columnNumber) attributes.push("Column "+this.columnNumber); + return (this.name || "Error")+": "+this.message+((attributes.length > 0)? " ("+attributes.join(", ")+")" : "") + } + + return err; +}; + // Init and return a book Book.init = function(root) { var book = new Book(root); |