Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.closeSync error #156

Open
LiST-GIT opened this issue Mar 4, 2022 · 2 comments
Open

fs.closeSync error #156

LiST-GIT opened this issue Mar 4, 2022 · 2 comments

Comments

@LiST-GIT
Copy link

LiST-GIT commented Mar 4, 2022

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
Copy link
Author

LiST-GIT commented Mar 4, 2022

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

@mfukala
Copy link

mfukala commented Feb 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants