Skip to content

Commit

Permalink
Implement filed executer error listner
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomohito Nakayama committed Feb 22, 2016
1 parent d0699b5 commit 9f4bedf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
31 changes: 17 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ module.exports.filed =
}

function filedExecuter( file ){

let thisExecuter = this;
if(file == null){
raiseError( this, 'File is needed.' );
}

this.executeChild = function(p1,p2){};

Expand All @@ -44,7 +42,7 @@ function filedExecuter( file ){
this.pass = addChildExecuterFunction(executerFactory(passExecuter,thisExecuter),this);
this.filter = addChildExecuterFunction(executerFactory(filterExecuter,thisExecuter),this);

this.exec = function(){ filedExecute( file, thisExecuter.executeChild ); };
this.exec = function(){ filedExecute( file, thisExecuter.executeChild, thisExecuter); };

};

Expand Down Expand Up @@ -184,23 +182,28 @@ function addChildExecuterFunction( executerFactory, parent ){
}


function filedExecute( file, execute ){
let itr = pathIterator( file );
function filedExecute( file, execute, filedExecuter){
let itr = pathIterator( file, filedExecuter);
for( let filePath of itr ){
execute(filePath, calcJb(filePath) );
}
}

function pathIterator( file ){
if ( typeof file == 'string' ){
return singlePath(file);
function pathIterator( file, filedExecuter){
try{
if ( typeof file == 'string' ){
return singlePath(file);
} else if ( file[ Symbol.iterator ] ) {
return file;
} else {
throw new Error();
}
} catch ( error ) {
raiseError( filedExecuter, 'Failed to create path Iterator' );
}

} else if ( file[ Symbol.iterator ] ) {
return file;
return [];

}else{
raiseError( null, 'Failed to create path Iterator' );
}
}

function * singlePath( file ){
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('Function return null', function () {
describe('Null file Path', function () {
it('should cause JsonFiledError', function (done) {
try{
jf.filed( null );
jf.filed( null ).exec();
}catch(e){
expect(e).to.be.an.instanceof( jf.JsonFiledError );
done();
Expand Down
8 changes: 7 additions & 1 deletion test/unit/testError.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('Error ', function () {
}
);

jf.filed(null,
function(err){
expect(err.msg).to.eql('Failed to create path Iterator');
}
).exec();

jf.filed( testPath )
.io(
function( obj, filePath) {
Expand All @@ -34,7 +40,7 @@ describe('Error ', function () {
}
).pass(
function(obj, filePath, executer){
executer.emit( 'error', errorObj ); //user can explicitly make executer to emit error
executer.emit( 'error', errorObj ); //user can explicitly make executer to emit error
},
function(err){
expect( err ).to.eql(errorObj);
Expand Down

0 comments on commit 9f4bedf

Please sign in to comment.