Cluster object was closed AKA how to properly verify connection

I don’t understand how to properly make AND VERIFY a connection to a Couchbase cluster.

Am I correct in assuming that literally the ONLY way to even verify a cluster connection is to actually attempt to read data from a bucket?

If I’m wrong, how does one confirm a bad connection string?

 const cb = require('couchbase')
 const cluster = new cb.Cluster('couchbase://localhost', {
            username: 'goodusername',
            password: 'badpassword'
//connect to bucket, but no error callback and no promise?
//is this really the way?
 try {
    await cluster.query(`SELECT * FROM mybucket WHERE meta().id = 'x'`)
} catch (err) {
   //The SDK appears to simply return a useless error message  Error: cluster object was closed.
    console.error(`Error connecting to Couchbase: ${err}. No idea what you should do now.`)
1 Like

Hello @Robert_Mirabelle that is correct the connection is to the cluster happens only when you start using it. Regarding the error message, that needs to be investigated further @ericb any comments ?

Thanks AV.

I’d really like to see something like cluster.testConnection() added to the driver. I understand the purpose of waiting till the last possible moment to engage the connection, but having to execute a “noop” query and then catch the possible error just to verify a connection string feels like a ‘hack’. I don’t want to read data from a bucket. I just want to verify my connection string is good and that’s it.

1 Like