gripe: deprecating fs.exists/existsSync
After noticing in the node docs that fs.exists and fs.existsSync were going to be deprecated, I took at look at the iojs docs to see that it had in fact been.
This is really annoying and seems like it's based out of the assumption that every developer ever is only checking the existence of a file prior to reading/writing in some async context. While I understand the sentiment behind wanting to avoid 'unnecessary abstractions' or race conditions, this is unnecessary.
Whereas I was previously able to handle the checking of a file's existence with a single boolean variable, I'm now given no other option but to either try/catch or make my code async and listen for error events.
This feels like prescriptivism, as I can't think of a single reason why a stern warning of the potential implications and/or examples of caveats to its use wouldn't have sufficed.
Can anyone help me understand why this was necessary (beyond pushing the all-async-all-the-time paradigm (that doesn't always necessarily apply (particularly in the case of synchronous CLI tooling)))?
Or perhaps can I just submit a PR that un-deprecates this perfectly good functionality?
EDIT: I am happy to provide any additional documentation that is deemed necessary.
This is really annoying and seems like it's based out of the assumption that every developer ever is only checking the existence of a file prior to reading/writing in some async context.
That's not quite how it is.
See fs.exists() in the docs .. it's been replaced by fs.access()
See #114 for more reference.
Reason being: fs.exists() used an API format that was unlike anything else in our API, and could produce results that were unexpected to those who didn't otherwise know.
fs.access doesn't seem like a replacement given that it also throws when there are any accessibility checks that fail. I don't want/need to do error handling every time I check for a file's existence. I don't think it's fair to call this a replacement.
I'm now given no other option but to either try/catch or make my code async and listen for error events.
That would be correct.
OK, close the issue before I can even reply? Awesome!
Deprecation with this kind of logic/motivation is only going to serve to make this platform less hospitable to people doing things outside of what features core is focused on.
I still don't see any reason why thorough documentation isn't an adequate response to any of the concerns that have been mentioned thus far.
I'm also pretty concerned at the realization that this is how we're treating issues created around valid questions/concerns.
Slapping down an open issue within 20 minutes of its creation is pretty hostile.
Original discussion can be found at https://github.com/joyent/node/pull/8418 & #103
Slapping down an open issue within 20 minutes of its creation is pretty hostile.
The GitHub close issue button is in the same location a cancel button usually is. This isn't uncommon for people to occasionally do. Is the intent not clear since I directly re-opened it? :/
If you're concerned about having to do a try-catch everywhere for fs.accessSync(), why not just make your own wrapper function(s)?:
var fs = require('fs');
function existsSync(filename) {
try {
fs.accessSync(filename);
return true;
} catch(ex) {
return false;
}
}
function exists(filename, cb) {
fs.access(filename, cb);
// or if want exactly the same old API:
//fs.access(function(err) { cb(err ? false : true); });
}
or why not leave the wrapper the way it is and let me continue to use fs.existsSync? :smile_cat:
perfectly good functionality?
or why not leave the wrapper the way it is and let me continue to use fs.existsSync?
That same thinking can be applied to just adding more and more sugar to core too. There is plenty discussion in the issues I liked above. At minimum, it wasn't particularly perfect, but it wasn't broken either.
As previously mentioned, the majority use case for fs.exists()/fs.existsSync() was to check if a file existed before opening a file. Removing it and recommending people just use fs.open()/fs.openSync() solves the problems associated with that majority use case.
@Fishrock123 let's discuss how we can make it good enough to leave in.
Should I create a new issue, or can we discuss the things that need to be improved on this one?
This has been discussed to death already. Moving to close.
@bnoordhuis How about if you're tired of discussing this particular issue: don't involve yourself.
Kind of hard to do when I get 15 new emails in the 30 minutes I'm away from my computer... at any rate, my point is that you're unlikely to bring up anything that hasn't been brought up before.
@bnoordhuis understandable. Apologies for contributing to your inbox spam.
I'll take a look at the source, read up on previous conversations, and see what I can do to help fix this.
I made a module for this as there's still genuine use-cases for checking if a file exists without reading the file afterwards.