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 not rejected on CastError #3512

Closed
gvelo opened this issue Oct 27, 2015 · 2 comments
Closed

Promise not rejected on CastError #3512

gvelo opened this issue Oct 27, 2015 · 2 comments

Comments

@gvelo
Copy link

gvelo commented Oct 27, 2015

There is a inconsistent behavior in the API related to error handling on callback vs promise flow.

In the following code, onRejected is never called and a MongooseError ( CastError ) is thrown

doc.update(  { _id: 'foo' }, {  $push:{ bar: value} } ).then( onFulfilled , onRejected )

But in the callback variant the callback function is called properly with the error.

doc.update(  { _id: 'foo' }, {  $push:{ bar: value} },  callback )
@vkarpov15 vkarpov15 added this to the 4.2.4 milestone Oct 28, 2015
@vkarpov15
Copy link
Collaborator

Thanks for pointing this out, will fix.

vkarpov15 added a commit that referenced this issue Nov 2, 2015
@vkarpov15
Copy link
Collaborator

So this would qualify as a backwards breaking change, because I would imagine some people still do

try {
  query = Model.update({ _id: 'foo' });
} catch(err) {}

query.exec();

because that's part of mongoose's API. That will change in 5.0, however, till then,

doc.update(  { _id: 'foo' }, {  $push:{ bar: value} }, { dontThrowCastError: true } ).then( onFulfilled , onRejected )

is the best we can do for 4.2.4 unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants