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

PromisifyAll failing on fs.readFileAsync #407

Closed
samccone opened this issue Dec 13, 2014 · 3 comments
Closed

PromisifyAll failing on fs.readFileAsync #407

samccone opened this issue Dec 13, 2014 · 3 comments

Comments

@samccone
Copy link
Contributor

If a file exists we get a fun error of

Possibly unhandled Error: true
  at maybeWrapAsError (/Users/sam/Desktop/repos/x/node_modules/bluebird/js/main/util.js:118:12)
  at PromiseResolver$_callback (/Users/sam/Desktop/repos/x/node_modules/bluebird/js/main/promise_resolver.js:54:50)
  at Object.cb [as oncomplete] (fs.js:168:19)

Reproduce with

Promise = require('bluebird')
fs = Promise.promisifyAll(require('fs'))
fs.existsAsync('/usr/share/dict/words').then(console.log.bind(console))

This is obviously due to the weird way fs.exists works.. just stinks :(
http://nodejs.org/api/fs.html#fs_fs_exists_path_callback

@petkaantonov
Copy link
Owner

Use .statAsync or anything else really, you should not use exists for anything, the docs even say that:

fs.exists() is an anachronism and exists only for historical reasons. There should almost never be a reason to use it in your own code.

@benjamingr
Copy link
Collaborator

Related nodejs/node#103

@samccone
Copy link
Contributor Author

Yep what I ended up doing @petkaantonov just wanted to document it here.

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

3 participants