Invalid `rejected with a non-error` warning
See original GitHub issueWhen 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:
- Created 7 years ago
- Comments:27 (13 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
Remove
Object.freeze(e)
from lib/ext/batch.js - bluebird expects that thestack
property is writable whenlongStackTraces
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
you get a clearer error: