-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Connection#open() promise rejection is broken #5229
Milestone
Comments
As a workaround, add an const mongoose = require('mongoose');
const conn = mongoose.createConnection(); // don't open now
conn.on('error', () => {}); // Add an error handler to prevent the exception
async function start() {
try {
await conn.open('some wrong connection string');
// this promise will throw
// but before that an error event is emitted, leading to an uncaught exception
} catch (error) {
console.log('error on open conn');
}
}
start(); |
vkarpov15
added a commit
that referenced
this issue
May 8, 2017
vkarpov15
added a commit
that referenced
this issue
May 10, 2017
vkarpov15
added a commit
that referenced
this issue
May 10, 2017
vkarpov15
added a commit
that referenced
this issue
May 12, 2017
vkarpov15
added a commit
that referenced
this issue
May 12, 2017
vkarpov15
added a commit
that referenced
this issue
May 12, 2017
Fix will be in 4.9.9. Monkey-patching |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
When
Connection#open()
fails, it is emitting an error event that turns into an uncaught exception, breaking the promise rejection handling.If the current behavior is a bug, please provide the steps to reproduce.
I'm guessing the problem is here:
mongoose/lib/connection.js
Line 316 in 2dd76ab
That
promise.$hasHandler
is not valid here, once$hasHandler
is a property ofMongooseThenable
instances (which is not the case there).This affects
Connection#openSet()
too.What is the expected behavior?
While open returns a promise, I expect that any error appears only as the rejection reason and not thrown somewhere else.
Please mention your node.js, mongoose and MongoDB version.
node.js: v7.10.0
mongoose: v4.9.7
MongoDB: v3.4.3
The text was updated successfully, but these errors were encountered: