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

How to catch connection errors? #295

Closed
maximilian-krauss opened this issue Sep 21, 2016 · 2 comments
Closed

How to catch connection errors? #295

maximilian-krauss opened this issue Sep 21, 2016 · 2 comments

Comments

@maximilian-krauss
Copy link

maximilian-krauss commented Sep 21, 2016

Hi,
I'm trying to use the rethinkdbdash driver with an express app. As long as the database connection details are correct all works pretty well. But as soon as the password is wrong (for example) the whole connection crashes and it does not invokes the catch method from the promise it returns.
How do I catch these errors?

I put together a little example on how you can reproduce the behavior:

'use strict';

let r = require('rethinkdbdash')({
  pool: true,
  db: 'this-db-exists',
  user: 'admin',
  silent: true,
  password: 'i-am-wrong',
  servers: [{
    host: '192.168.xx.xxx',
    port: 28015
  }]
});

r.table('content')
  .getAll()
  .run()
  .then(function(results) {
    console.log(results);
  })
  .catch(function(err) {
    console.log('oh no, i do not get called :-(');
  });

/* This is what it prints out in the console
Unhandled rejection ReqlDriverError: Error 12:Wrong password.
    at Socket.<anonymous> (/Users/max/test/rdbdash/node_modules/rethinkdbdash/lib/connection.js:176:20)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at Socket.Readable.push (_stream_readable.js:111:10)
    at TCP.onread (net.js:536:20)
*/

node: 4.5
rethinkdbdash: 2.3.23

Regards,
Max

@neumino
Copy link
Owner

neumino commented Oct 7, 2016

Sorry, missed that issue.

The short answer is you can't catch this specific error though it shouldn't be an unhanded error.

@neumino
Copy link
Owner

neumino commented Oct 7, 2016

(that is to say it's a bug, the error in your catch should be something like no pools have available connections and we failed to open one)

@neumino neumino closed this as completed Oct 18, 2016
@neumino neumino reopened this Oct 18, 2016
@neumino neumino closed this as completed in e5644bb Nov 6, 2016
thejsj added a commit to thejsj/rethinkdbdash that referenced this issue Dec 17, 2016
* 'master' of github.com:neumino/rethinkdbdash: (304 commits)
  Fix leaked variable from test
  Bump to 2.3.27
  Fix neumino#313
  Bump to 2.3.26
  fix: return null where new Promises are created but not returned
  Fix leak in tests
  Fix leak in tests
  Bump to 2.3.25
  Make identification errors operational such that they can be properly caught - Fix neumino#295
  Bump to 2.3.24
  Close the stream if an error is emitted since we can't recover frm it
  Remove the use of Buffer with new for node 7 - Fix neumino#304
  Wrap sending the proof in a try/catch in case the connection is closed - Fix neumino#296
  Bump to 2.3.23
  Prevent bluebird warning - Fix neumino#287
  Bump to 2.3.22
  Prevent bluebird warning - Fix neumino#285
  function r: remove unused parameter `options`
  readme: minor typo fix
  Bump to 2.3.21
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants