Created
November 9, 2015 17:24
-
-
Save thisconnect/634cf0c670daa8ea4a28 to your computer and use it in GitHub Desktop.
fs.close twice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open 10 | |
close - should have no error | |
close2 - should have error | |
{ [Error: EBADF: bad file descriptor, close] errno: -9, code: 'EBADF', syscall: 'close' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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