99
1010 var
1111 reportList = [ ] ,
12- walker = walk . walk ( path )
12+ walker = walk . walk ( path ) ,
13+ errStack = null
1314 ;
1415
1516 walker
1617 . on ( "file" , function ( root , fileStats , next ) {
1718
1819 var fileRef = require ( 'path' ) . normalize ( root + "/" + fileStats . name ) ;
19- console . log ( fileRef ) ;
2020
2121 if ( ( / \. ( j s ) $ / i) . test ( fileRef ) ) {
22-
2322
2423 fs . readFile ( fileRef , 'utf8' , function ( err , data ) {
2524 if ( err ) throw new Error ( err , fileRef ) ;
26- var report = cr . run ( data ) ;
27- var toBeDisplayed = {
28- path : fileRef ,
29- escapedPath : fileRef . replace ( / \\ / g, '\\' ) , // windows use
30- complexity : report . aggregate . complexity . cyclomatic ,
31- lineNumber : report . aggregate . complexity . sloc . physical ,
32- maintainability : report . maintainability ,
33- halstead : {
34- length : report . aggregate . complexity . halstead . length ,
35- vocabulary : Math . round ( report . aggregate . complexity . halstead . vocabulary ) ,
36- difficulty : Math . round ( report . aggregate . complexity . halstead . difficulty ) ,
37- bugs : Math . round ( report . aggregate . complexity . halstead . bugs )
38- }
39- } ;
40- reportList . push ( toBeDisplayed ) ;
41- next ( ) ;
25+ try {
26+ var report = cr . run ( data ) ;
27+ var toBeDisplayed = {
28+ path : fileRef ,
29+ escapedPath : fileRef . replace ( / \\ / g, '\\' ) , // windows use
30+ complexity : report . aggregate . complexity . cyclomatic ,
31+ lineNumber : report . aggregate . complexity . sloc . physical ,
32+ maintainability : report . maintainability ,
33+ halstead : {
34+ length : report . aggregate . complexity . halstead . length ,
35+ vocabulary : Math . round ( report . aggregate . complexity . halstead . vocabulary ) ,
36+ difficulty : Math . round ( report . aggregate . complexity . halstead . difficulty ) ,
37+ bugs : Math . round ( report . aggregate . complexity . halstead . bugs )
38+ }
39+ } ;
40+ reportList . push ( toBeDisplayed ) ;
41+ next ( ) ;
42+ } catch ( e ) {
43+ if ( ! errStack ) errStack = [ ] ;
44+ errStack . push ( { ref : fileRef , error : e } ) ;
45+ next ( ) ;
46+ }
47+
4248 } ) ;
4349
4450 } else { next ( ) ; }
4551
4652 } )
47- . on ( "error" , function ( ) { cb ( err ) ; } )
48- . on ( "end" , function ( ) { cb ( null , reportList ) ; } )
53+ . on ( "error" , function ( ) { cb ( errStack , reportList ) ; } )
54+ . on ( "end" , function ( ) { cb ( errStack , reportList ) ; } )
4955 ;
5056
5157 }
0 commit comments