question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid `rejected with a non-error` warning

See original GitHub issue

When we set a message in out custom error object based on some non-string data, Bluebird displays Warning: a promise was rejected with a non-error: [object Object], which is clearly a mistake.

Here’s complete example:

'use strict';

var util = require('util');
var promise = require('bluebird');

function CustomError(data) {
    this.message = data;
    Error.captureStackTrace(this, CustomError);
}

util.inherits(CustomError, Error);
CustomError.prototype.name = 'CustomError';

promise.reject(new CustomError([]))
    .catch(error=> {
        console.log(error);
    });

This should not produce that warning, but it does.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
spioncommented, Jun 28, 2016

@vitaly-t Just don’t freeze the error. At the very least, leave the stack property writable, or don’t turn on longStackTraces.

By the way, I already wrote about this restriction yesterday, when you only quoted “No” from that text and LOLed. Last restriction was “the stack property needs to be writable”

https://github.com/petkaantonov/bluebird/issues/1146#issuecomment-228826885

This should definitely be in the docs, in some form.

2reactions
spioncommented, Jun 28, 2016

Remove Object.freeze(e) from lib/ext/batch.js - bluebird expects that the stack property is writable when longStackTraces are on.

(You’ll probably need to do it for lib/ext/sequence.js too, where its repeated as Object.freeze(error))

To make it easier to debug this, the freezing concern that modifies the error object should have been a part of the error unit/submodule. That way unit tests will be able to catch this.

Not sure whats going on other than that, when you run this in normal code that doesn’t attempt to do so much wrapping of bluebird behaviour

Promise.resolve()
.then(function() {
  var e = new Error();
  Object.freeze(e);
  throw e;
}).catch(function(error) {
  console.log("Caught: ", error.stack);
});

you get a clearer error:

TypeError: Cannot redefine property: stack
    at Object.defineProperty (native)
    at Object.notEnumerableProp (/node_modules/bluebird/js/release/util.js:97:9)
    at CapturedTrace.attachExtraTrace (/node_modules/bluebird/js/release/debuggability.js:725:10)
    at Promise.longStackTracesAttachExtraTrace [as _attachExtraTrace] (/node_modules/bluebird/js/release/debuggability.js:379:19)
    at Promise._rejectCallback (/node_modules/bluebird/js/release/promise.js:466:10)
    at Promise._settlePromiseFromHandler (/node_modules/bluebird/js/release/promise.js:513:17)
    at Promise._settlePromise (/node_modules/bluebird/js/release/promise.js:561:18)
    at Promise._settlePromiseCtx (/node_modules/bluebird/js/release/promise.js:598:10)
    at Async._drainQueue (/node_modules/bluebird/js/release/async.js:143:12)
    at Async._drainQueues (/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/node_modules/bluebird/js/release/async.js:17:14)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)
Read more comments on GitHub >

github_iconTop Results From Across the Web

a promise was rejected with a non-error: [object Array] · Issue ...
Working with native Promise i got this warning. Warning: a promise was rejected with a non-error: [object Array] If validation errors exists ......
Read more >
Getting Warning: a promise was rejected with a non-error
In the catch block I just console.log(err) or alert(err) . This happens when the app loads so I will post the promises that...
Read more >
Warning Explanations - Bluebird.js
Warning: a promise was rejected with a non-error​​ An error is an object that is a instanceof Error . It will at minimum...
Read more >
Developers - Invalid `rejected with a non-error` warning -
When we set a message in out custom error object based on some non-string data, Bluebird displays Warning: a promise was rejected with...
Read more >
CA state tax always got rejected even TurboTax checked and ...
CA state tax always got rejected even TurboTax checked and said no error (tried at least 8 times already). The email contains this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found