Skip to content

Instantly share code, notes, and snippets.

@thisconnect
Created November 9, 2015 17:24
Show Gist options
  • Save thisconnect/634cf0c670daa8ea4a28 to your computer and use it in GitHub Desktop.
Save thisconnect/634cf0c670daa8ea4a28 to your computer and use it in GitHub Desktop.
fs.close twice
open 10
close - should have no error
close2 - should have error
{ [Error: EBADF: bad file descriptor, close] errno: -9, code: 'EBADF', syscall: 'close' }
var assert = require('assert');
var fs = require('fs');
// 'w+' - Open file for reading and writing.
// The file is created (if it does not exist)
// or truncated (if it exists).
fs.open(__dirname + '/test-to-open-a-file.txt', 'w+', function(err1, fd){
console.log('open', fd);
fs.close(fd, function(err2){
console.log('close - should have no error');
assert.ifError(err2);
fs.close(fd, function(err3){
console.log('close2 - should have error');
console.error(err3);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment