spyfs icon indicating copy to clipboard operation
spyfs copied to clipboard

fs.closeSync error

Open LiST-GIT opened this issue 3 years ago • 2 comments

javascript const spyfs = require( 'spyfs' ); const sfs = spyfs.spy( fs, action => { console.log( action ); } ); const fd = sfs.openSync( __filename, 'r' ); sfs.closeSync( fd ); // error, return undefined

LiST-GIT avatar Mar 04 '22 10:03 LiST-GIT

const spyfs = require( 'spyfs' );
const sfs = spyfs.spy( fs, action => { console.log( action ); } );
const fd = sfs.openSync( __filename, 'r' );
sfs.closeSync( fd ); // error, return undefined

LiST-GIT avatar Mar 04 '22 10:03 LiST-GIT

I can reproduce the same problem with any sync method that does not return a value like fs.writeFileSync(). The bug is in Spy's #returnOrThrow function. When I change

function returnOrThrow() {
    if (typeof result !== 'undefined') {
        return result;
    } else {
        throw error;
    }
}

to more meaningful

function returnOrThrow() {
    if(error) {
        throw error;
    } else {
        return result;
    }
}

everything work fine.

mfukala avatar Feb 05 '24 12:02 mfukala