pass `null` as the second argument to request, and an object as the first argument, it will fail #205

Closed
jmarca opened this Issue Mar 12, 2012 · 1 comment

2 participants

@jmarca

I've been doing something wrong that used to work and now fails. possible bug, most likely a programming mistake on my part, but perhaps the docs should make a note so as to prevent this in the future.

If you pass null as the second argument to request, and an object as the first argument, it will fail. For example:

var cuser =  process.env.COUCHDB_USER ;
var cpass =  process.env.COUCHDB_PASS ;
var chost =  process.env.COUCHDB_HOST ;
var cport =  process.env.COUCHDB_PORT || 5984;

var options={'headers':{}
             ,'uri': 'http://127.0.0.1:5984/safetynet%2frisk/_design/anyaccident/_view/day_id?startkey=%5B2007%2C1%2C2%5D&endkey=%5B2007%2C1%2C3%5D&reduce=false'
             ,'method':'GET'
            };
options.headers.authorization = "Basic " + new Buffer(cuser + ":" + cpass).toString('base64');
options.headers.accept='application/json';
var r = request(options,null);

That will fail.

I am piping the output t from couchdb, so I don't really need the callback function. I've been passing null, but I noticed today that with request@2.9.153 that breaks with the error:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot set property 'uri' of null
    at request (/home/james/node_modules/request/main.js:793:17)
    at Object.<anonymous> (/home/james/requestfail.js:15:9)
   ...

Passing nothing as the second argument works fine:

var r = request(options);
r.pipe(...)
@mikeal
request member

Is this still an issue?

This is so old I'm closing, if it is actually still an issue just let me know and I'll re-open.

@mikeal mikeal closed this Aug 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment