@@ -235,8 +235,15 @@ Book.prototype.generate = function(generator) {
235235 return _ . reduce ( ops [ "content" ] || [ ] , function ( prev , file , i ) {
236236 return prev . then ( function ( ) {
237237 var p = ( ( i * 100 ) / nFiles ) . toFixed ( 0 ) + "%" ;
238- that . log . info . ln ( "processing" , file , p ) ;
239- return Q ( generator . convertFile ( file ) ) ;
238+ that . log . debug . ln ( "processing" , file , p ) ;
239+
240+ return Q ( generator . convertFile ( file ) )
241+ . fail ( function ( err ) {
242+ // Transform error message to signal file
243+ throw that . normError ( err , {
244+ fileName : file
245+ } ) ;
246+ } ) ;
240247 } ) ;
241248 } , Q ( ) ) ;
242249 } ) ;
@@ -734,6 +741,32 @@ Book.prototype.i18n = function(phrase) {
734741 return i18n . __ . apply ( { } , [ this . config . normalizeLanguage ( ) ] . concat ( args ) ) ;
735742} ;
736743
744+ // Normalize error
745+ Book . prototype . normError = function ( err , opts ) {
746+ opts = _ . defaults ( opts || { } , {
747+
748+ } ) ;
749+
750+ if ( _ . isString ( err ) ) err = new Error ( err ) ;
751+
752+ // Extend err
753+ _ . extend ( err , opts ) ;
754+
755+ err . lineNumber = err . lineNumber || err . lineno ;
756+ err . columnNumber = err . columnNumber || err . colno ;
757+
758+ err . toString = function ( ) {
759+ var attributes = [ ] ;
760+
761+ if ( this . fileName ) attributes . push ( "In file '" + this . fileName + "'" ) ;
762+ if ( this . lineNumber ) attributes . push ( "Line " + this . lineNumber ) ;
763+ if ( this . columnNumber ) attributes . push ( "Column " + this . columnNumber ) ;
764+ return ( this . name || "Error" ) + ": " + this . message + ( ( attributes . length > 0 ) ? " (" + attributes . join ( ", " ) + ")" : "" )
765+ }
766+
767+ return err ;
768+ } ;
769+
737770// Init and return a book
738771Book . init = function ( root ) {
739772 var book = new Book ( root ) ;
0 commit comments