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

Promise.promisifyAll doesn't work for some methods #156

Closed
louwers opened this issue Jul 28, 2015 · 4 comments
Closed

Promise.promisifyAll doesn't work for some methods #156

louwers opened this issue Jul 28, 2015 · 4 comments

Comments

@louwers
Copy link

louwers commented Jul 28, 2015

Hi there!

Since it is mentioned in the README that fs-extra's methods can be promisified with bluebird's promisifyAll method, I figured out that I should report the following: not all methods seem to be promisified correctly with that method.

As far as I can tell, .readJson is one such method.

Using var fs = Promise.promisifyAll(require('fs-extra')) yields the following error upon evoking fs.readJson:

/path/node_modules/jsonfile/index.js:19
    callback(null, obj)
    ^
TypeError: undefined is not a function
    at /path/node_modules/jsonfile/index.js:19:5
    at fs.js:334:14
    at FSReqWrap.oncomplete (fs.js:95:15)

On the other hand, using var fs = require('fs') and later fs.readJson = Promise.promisify(fs.readJson) works fine for me. I therefore suggest warning users that some methods need to be promisified individually in order to work, if others are able to reproduce this problem, that is. Note that fs-extra-promise is also affected by this.

Note that I am using Promises in async/await functions with Babel, so there is a real possibility that those that are just using Promises with bluebird do not experience the same problem.

@jprichardson
Copy link
Owner

It's because promsifyAll appends Async to the method names.

See this snippet:

var Promise = require('bluebird')
var fs = require('fs-extra')
var fsp = Promise.promisifyAll(fs)
fsp.readJsonAsync('./package.json')
.then(function (obj) {
  console.dir(obj)
})
.catch(function (err) {
  console.error(err)
})

@louwers
Copy link
Author

louwers commented Jul 29, 2015

Thank you for enlightening me.
Lesson learned: RTFM.

@jprichardson
Copy link
Owner

It's ok, we've all been there :)

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

2 participants