-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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.exists doesn't promisify into a good fs.existsAsync #418
Comments
FWIW, there should be no reason to use |
That is a known comment. Example good use, however: At server startup after creating directory for uploads verify it exists and fail if not, e.g. lacking privileges. Don't let a server start up only to fail on first upload. |
Yes it is a common issue, I would accept pull request that mentions it in the |
in the next io.js On Mon, Dec 29, 2014 at 1:38 AM, Petka Antonov notifications@github.com
|
Better workaround:
Example code proving it works:
producing output:
|
Warn regarding fs.existsAsync per #418
yeah I was look at the docs here https://nodejs.org/api/fs.html#fs_fs_exists_path_callback I will never understand why they didn't use an error-first callback for this one: fs.exists('myfile', (exists) => { // really, no error-first callback huh?
if (exists) {
console.error('myfile already exists');
} else {
fs.open('myfile', 'wx', (err, fd) => {
if (err) throw err;
writeMyData(fd);
});
}
}); so weird |
Maybe should be mentioned in documentation.
Problem with promisifyAll of Node's fs for method fs.existsAsync.
Obvious reason: fs.exists doesn't callback with an err for first argument, just the result.
Workaround for many uses: Use
fs.stat
instead.Example code to illustrate problem:
with bluebird 2.5.0 (and 2.4.3) produces output
which means result true gets wrapped as an error.
The text was updated successfully, but these errors were encountered: