cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

Error in Bluemix nano.use = nano.db.use = use; #96

Closed geekosphere-net closed 8 years ago

geekosphere-net commented 9 years ago

Just tried to include 1.3.x into my project in Bluemix and got the following stack error:

2015-09-04T11:20:12.40-0400 [App/0] ERR /home/vcap/app/node_modules/cloudant/cloudant.js:150 2015-09-04T11:20:12.40-0400 [App/0] ERR nano.use = nano.db.use = use; 2015-09-04T11:20:12.40-0400 [App/0] ERR ^ 2015-09-04T11:20:12.40-0400 [App/0] ERR TypeError: Cannot set property 'use' of undefined 2015-09-04T11:20:12.40-0400 [App/0] ERR at Cloudant (/home/vcap/app/node_modules/cloudant/cloudant.js:150:26) 2015-09-04T11:20:12.40-0400 [App/0] ERR at Object. (/home/vcap/app/app.js:13:10) 2015-09-04T11:20:12.40-0400 [App/0] ERR at Module._compile (module.js:460:26) 2015-09-04T11:20:12.40-0400 [App/0] ERR at Object.Module._extensions..js (module.js:478:10) 2015-09-04T11:20:12.40-0400 [App/0] ERR at Module.load (module.js:355:32) 2015-09-04T11:20:12.40-0400 [App/0] ERR at Function.Module._load (module.js:310:12) 2015-09-04T11:20:12.40-0400 [App/0] ERR at Function.Module.runMain (module.js:501:10) 2015-09-04T11:20:12.40-0400 [App/0] ERR at startup (node.js:129:16) 2015-09-04T11:20:12.40-0400 [App/0] ERR at node.js:814:3

karolszafranski commented 9 years ago

I had the same error. Logs are saying that nano object do not exist. In my case this happen cause I used wrong username. Lib nano, which is base of this library, was unable to connect so constructor returned nothing. This library assumes that everything goes ok and just keeps doing its job without checking for error there.

I'm talking about 75 line of cloudant.js rev 1.3.0.

glynnbird commented 9 years ago

Thanks for pointing this out. We'll take a look. We are going to reorganise this library's relationship to the Nano library to improve the way they are inter-related, but in the meantime we should check for this error condition.

glynnbird commented 9 years ago

In fact, looking at this a bit more closely, if call the library like this:

var Cloudant = require('cloudant');

// Initialize the library with my account.
var cloudant = Cloudant({ url: "https://myuser:mybadpassword@myaccount.cloudant.com"}, function(err, data) {
  console.log(err,data);
});

Then I get a clean value of err passed to me.

If I opt for the synchronous instantiation of the library I get a clean error too when I come to use the object for the first time:

var Cloudant = require('cloudant');

var cloudant = Cloudant({ url: "https://myuser:mybadpassword@myaccount.cloudant.com"});
var db = cloudant.db.use("mydb");
db.list(function(err, data){
   console.log(err,data);
});
monte-hayward commented 9 years ago

Any progress on this? It is a blocker.

monte-hayward commented 9 years ago

/usr/local/bin/node --debug-brk=56687 --nolazy myServer.js Debugger listening on port 56687 /path/to/node_modules/cloudant/cloudant.js:150 nano.use = nano.db.use = use; ^ TypeError: Cannot set property 'use' of undefined at Cloudant (/path/to/node_modules/cloudant/cloudant.js:150:26) at Object.<anonymous> (/path/to/client/brando.js:19:16) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.runMain [as _onTimeout] (module.js:501:10) at Timer.listOnTimeout (timers.js:119:15)

glynnbird commented 8 years ago

I notice this happening if you instantiate the library with a Cloudant URL that includes a database e.g.

var cloudant = Cloudant("https://myaccount.cloudant.com/mydb");

instead of doing

var cloudant = Cloudant("https://myaccount.cloudant.com");
var mydb = cloudant.db.use("mydb");
jgentes commented 7 years ago

For the record, after setting up a new instance of cloudant on Bluemix, this is what ended up working for me:

var Cloudant = require('cloudant');
var cloudant = Cloudant({
      account: 'asdfasdf-bluemix',
      key: 'asdfdasf',
      password: 'sadfsaf'});
var cdb = cloudant.db.use("communities-dev");

The API key and password can be generated from the /permissions page on the Cloudant dashboard.