title: Catch fails on connection to Mongo
body: <p>the answer to this question: <a href="https://stackoverflow.com/questions/50241066/how-to-get-node-to-exit-when-mongo-connect-fails/50241149">How to get node to exit when mongo connect fails</a> contains async/wait code for a connection</p>
  
  <p>however, my code (running on node v11.5.0 and mongodb v3.1.13) is failing to catch:</p>
  
  <pre><code>(async function() {
    let db; 
    try {
      db = await MongoClient.connect(uri, { useNewUrlParser: true }); 
      console.log("RETURN", db);
    } catch (err) {
      console.log('EXITING');
      process.exit(1);
    }
  }());
  </code></pre>
  
  <p>to prove the point I intentionally give a uri without credentials:</p>
  
  <blockquote>
    <p>mongodb://undefined@cluster0-shard-00-00-z4j9e.azure.mongodb.net:27017,cluster0-shard-00-01-z4j9e.azure.mongodb.net:27017,cluster0-shard-00-02-z4j9e.azure.mongodb.net:27017/test?ssl=true&amp;replicaSet=Cluster0-shard-0&amp;authSource=admin&amp;retryWrites=true</p>
  </blockquote>
  
  <p>and what I get is output like this:</p>
  
  <blockquote>
    <p>/Users/ekkis/dev/mongo/node_modules/mongodb/lib/topologies/replset.js:346
       throw err;
       ^</p>
    
    <p>MongoError: password must be a string
        at passwordDigest (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/auth/scram.js:63:43)
        at ScramSHA1.ScramSHA.auth (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/auth/scram.js:175:25)
        at authenticate (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/connection/pool.js:232:17)
        at authenticateLiveConnections (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/connection/pool.js:819:7)
        at /Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/connection/pool.js:864:5
        at waitForLogout (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/connection/pool.js:855:34)
        at Pool.auth (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/connection/pool.js:862:3)
        at Server.auth (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/topologies/server.js:931:20)
        at auth (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/topologies/replset.js:1474:19)
        at ReplSet.auth (/Users/ekkis/dev/mongo/node_modules/mongodb-core/lib/topologies/replset.js:1492:5)</p>
  </blockquote>
  
  <p>so if the error had been caught, the console should have displayed the word 'EXITING', but does not.  additionally, I contend an exception was thrown because otherwise the returned value would have been printed, which it was not</p>
  
  <p>how can this be? what do I need to do to get it to work?</p>
  
  <p><strong>* Appendix I *</strong></p>
  
  <p>In fact, the promises version of this exhibits the same odd behaviour, it doesn't catch:</p>
  
  <pre><code>MongoClient
    .connect(uri, { useNewUrlParser: true })
    .then(dbc =&gt; {
      console.log('SUCCESS');
      })
    .catch(err =&gt; {
      console.log('EXITING');
      process.exit(1);
    });
  </code></pre>
  
  <p>and yes, I tested the callback version, which also suffers the same malady.  Incidentally, passing an empty string for the uri works well.  I don't get it</p>
  
  <p><strong>* Appendix II *</strong></p>
  
  <p>In fact, the problem seems to be particular to the credentials passed i.e. if I pass:</p>
  
  <blockquote>
    <p>mongodb://x:y@cluster0-shard-[...]</p>
  </blockquote>
  
  <p>I catch a "MongoError: authentication fail" as expected.  passing:</p>
  
  <blockquote>
    <p>mongodb://@cluster0-shard-[...]</p>
  </blockquote>
  
  <p>interestingly returns a connection but credentials missing a ":" fail in this odd way, so:</p>
  
  <blockquote>
    <p>mongodb://ekkis@cluster0-shard-[...]</p>
  </blockquote>
  
  <p>fails to catch</p>