Error: Promise.promisify called on an object

You got this this error because you've used Promise.promisify on an object, for example:

var fs = Promise.promisify(require("fs"));

Instead, use Promise.promisifyAll :

var fs = Promise.promisifyAll(require("fs"));

Error: the promise constructor requires a resolver function

You got this error because you used new Promise() or new Promise(something) without passing a function as the parameter.

If you want to wrap an API with a promise manually, the correct syntax is:

function wrapWithPromise(parameter) {
    return new Promise(function (resolve, reject) {
        doSomethingAsync({
              error:reject,
              success:resolve
        });
    });
}

Please consider reading about new Promise and also consider checking out automatic promisification as well as Promise.method

Error: the promise constructor cannot be invoked directly

You can get this error for several reasons:

1. You forgot to use new when creating a new promise using new Promise(resolver) syntax.

This can happen when you tried to do something like:

return Promise(function(resolve,reject){
       //...
})

You can correct this by doing:

return new Promise(function(resolve,reject){
       //...
})

Please consider reading about new Promise and also consider checking out automatic promisification as well as Promise.method

2. You are trying to subclass Promise

Bluebird does not support extending promises this way. Instead, see scoped prototypes.

Error: expecting an array, a promise or a thenable

The function being called expects a Promise, but is given something different. There are two main reasons why this may occur.

1. Working with collections (like arrays) but pass a single, non-collection element instead

Example:

function returnThree(){ return 3;}

Promise.resolve(5).map(returnThree).then(function(val){
     console.log("Hello Value!",val); 
});

The map operation is expecting an array here (or a promise on one) and instead gets the number 5.

function returnThree(){ return 3;}

Promise.resolve([5]).map(returnThree).then(function(val){
     console.log("Hello Value!",val); 
});

map is given an array with a single element (see [5] instead of 5), so this statement will work (but is bad practice).


2.return is forgotten in a 'fat' arrow / anonymous function call =>:

When debugging or performing a one-time operation on a variable before passing it to a function, a return variable is forgotten.

Example:

function nextFunction(something){ return Promise.resolve(something*3); }

myFunction()
    .then(result => nextFunction(result)); // We are implicitly returning a Promise

Debugging, we want to see the value of result, so we add a console.log() line:

function nextFunction(something){ return Promise.resolve(something*3); }

myFunction().then(result => {
    console.log("Debug:", result);
    nextFunction(result)); // The chain is broken! We don't return anything to the .then() call
});

As this is an anonymous function call, we need to return something, which is not currently happening.

To fix, simply remember to add return in front of your promise-complying function:

function nextFunction(something){ return Promise.resolve(something*3); }

myFunction().then(result => {
    console.log("Debug:", result);
    return nextFunction(result)); // The anonymous function returns the function which returns the promise .then() needs
});

Error: generatorFunction must be a function

You are getting this error when trying to use Promise.coroutine and not passing it a generator function as a parameter. For example:

Promise.coroutine(function* () { // Note the *
    var data = yield $.get("http://www.example.com");
    var moreUrls = data.split("\n");
    var contents = [];
    for( var i = 0, len = moreUrls.length; i < len; ++i ) {
        contents.push(yield $.get(moreUrls[i]));
    }
    return contents;
});

Please refer to the relevant section in the documentation about Generators in order to get usage instructions:

Note: Bluebird used to eagerly check for generators which caused problems with transpilers. Because of this, you might get an error similar to TypeError: Cannot read property 'next' of undefined if you pass a function instead of a generator function to Bluebird.

Promise.coroutine is built to work with generators to form C# like async/await

Error: fn must be a function

You passed a non-function where a function was expected.

Error: cannot enable long stack traces after promises have been created

You are getting this error because you are enabling long stack traces after a promise has already been created.

When using longStackTraces the first line in your code after requiring Bluebird should be:

Promise.config({
    longStackTraces: true
});

See the API page about Promise.longStackTraces

Error: cannot get fulfillment value of a non-fulfilled promise

You can get this error when you're trying to call .value or .error when inspecting a promise where the promise has not been fulfilled or rejected yet.

For example:

var p = Promise.delay(1000);
p.inspect().value();

Consider using .isPending() .isFulfilled() and .isRejected() in order to inspect the promise for status.

Please consider reading more about synchronous inspection

Error: cannot get rejection reason of a non-rejected promise

You can get this error when you're trying to call .value or .error when inspecting a promise where the promise has not been fulfilled or rejected yet.

For example:

var p = Promise.delay(1000);
p.inspect().value();

Consider using .isPending() .isFulfilled() and .isRejected() in order to inspect the promise for status.

Please consider reading more about synchronous inspection

Error: the target of promisifyAll must be an object or a function

This can happen when you are calling Promise.promisifyAll on a function and invoking it instead of passing it.

In general, the usage of Promise.promisifyAll is along the lines of var fs = Promise.promisifyAll(require("fs")).

Consider reading the section about promisification

Error: circular promise resolution chain

This usually happens when you have a promise that resolves or rejects with itself.

For example: var p = Promise.delay(100).then(function(){ return p}); .

In this case, the promise resolves with itself which was is not intended.

This also happens when implementing live-updating models with a .then method that indicates when the model is "ready". A promise is a process, it starts and it ends.

Promises do not aim to solve such live updating problems directly. One option would be to use an intermediate promise - for example a .loaded property on the model that fulfills with nothing.

resolving it with itself tells it "it is done when it is done"

Error: cannot await properties of a non-object

The .props method expects to receive an object.

For example:

Promise.props({
    pictures: getPictures(),
    comments: getComments(),
    tweets: getTweets()
}).then(function(result){
    console.log(result.tweets, result.pictures, result.comments);
});

This happens when a non object value or a promise that resolves with something that is not an object is being passed instead.

Error: expecting a positive integer

This happens when you call .some passing it a negative value or a non-integer.

One possible cause is using .indexOf which returns -1 when it doesn't find the value being searched for.

Please consider reading the API docs for .some

Error: A value was yielded that could not be treated as a promise

You are getting this error because you have tried to yield something in a coroutine without a yield handler, for example:

var coroutine = Promise.coroutine(function*(){
    var bar = yield "Foo";
    console.log(bar);
});

The solution is to either convert it to a promise by calling Promise.resolve on it or Promise.promisify if it's a callback:

var coroutine = Promise.coroutine(function*(){
    var bar = yield Promise.resolve("Foo");
    console.log(bar);
});

Or to use Promise.coroutine.addYieldHandler` to teach Promise.coroutine to accept these sort of values.

Error: cannot await properties of a non object

The .props method expects to receive an object.

For example:

Promise.props({
    pictures: getPictures(),
    comments: getComments(),
    tweets: getTweets()
}).then(function(result){
    console.log(result.tweets, result.pictures, result.comments);
});

This happens when a non object value or a promise that resolves with something that is not an object is being passed instead.

Error: Cannot promisify an API that has normal methods

This error indicates you have tried to call Promise.promisifyAll on an object that already has a property with the Async suffix:

var myApi = { foo: function(cb){ ... }, fooAsync(cb) { ... }

This is because Bluebird adds the Async suffix to distinguish the original method from the promisified one, so fooAsync would have been overridden. In order to avoid this - either rename fooAsync before promisifying the API, or call Promise.promisify manually on select properties.

You may also use the custom suffix option to choose another suffix that doesn't result in conflicts.

If you find this issue in a common library please open an issue.

Error: Catch filter must inherit from Error or be a simple predicate function

Bluebird supports typed and predicate .catch() calls]. However in order to use the typed/predicate catch syntax for error handling you must do one of two things.

Pass it a constructor that inherits from Error:

}).catch(ReferenceError, function(e) { // this is fine
}).catch(Array, function(e) { // arrays don't capture stack traces

This is to enable better stack trace support and to have more consistent and logical code.

Alternatively, if you provide it a predicate be sure it's a simple function:

}).catch(function(e){ return false; }, function(e) { // this catches nothing
}).catch(function(e){ return e.someProp = 5; }, function(e) { // this is fine

Please see the API docs of .catch() on how to use predicate catches.

Error: No async scheduler available

Async scheduler is a function that takes a callback function and calls the callback function as soon as possible, but asynchronously. For example setTimeout.

By default bluebird only tries a few common async schedulers, such as setTimeout, process.nextTick and MutationObserver. However if your JavaScript runtime environment doesn't expose any of these, you will see this error.

You may use Promise.setScheduler to pass a custom scheduler that your environment supports. For example in DukTape:

Promise.setScheduler(function(fn){ // fn is what to execute
    var timer = uv.new_timer.call({});
    uv.timer_start(timer, 0, 0, fn); // add the function as a callback to the timer
});