Description
I'm suddenly having an issue with .return()
in exactly 2.9.31
.
exports.has = (name, callback) ->
exports.get(name).return(true)
.catch errors.ResinApplicationNotFound, ->
return false
.nodeify(callback)
If exports.get()
resolves, then the promise is resolved as an empty object {}
instead of true
.
Switching to .then()
fixes the issue:
exports.has = (name, callback) ->
exports.get(name).then ->
return true
.catch errors.ResinApplicationNotFound, ->
return false
.nodeify(callback)
I've created a branch in my project (https://github.com/resin-io/resin-sdk/tree/issue/bluebird-return) locking to 2.9.31
which reproduces the issue (reverting to 2.9.30
fixes the issue).
$ git clone https://github.com/resin-io/resin-sdk
$ cd resin-sdk
$ git checkout issue/bluebird-return
$ gulp test
By running the test suite you should get something like:
2 failing
1) Application Model: .has() given an application should eventually be true:
AssertionError: expected {} to be true
2) Device Model: .has() given the device should eventually be true:
AssertionError: expected {} to be true
Application Model .has()
function definition: https://github.com/resin-io/resin-sdk/blob/issue/bluebird-return/lib/models/application.coffee#L104.
Application Model .has()
failing test: https://github.com/resin-io/resin-sdk/blob/issue/bluebird-return/tests/models/application.spec.coffee#L123.
Device model .has()
function definition: https://github.com/resin-io/resin-sdk/blob/issue/bluebird-return/lib/models/device.coffee#L180.
Device Model .has()
failing test: https://github.com/resin-io/resin-sdk/blob/issue/bluebird-return/tests/models/device.spec.coffee#L332.