needle icon indicating copy to clipboard operation
needle copied to clipboard

TypeError: callback is not a function

Open dhowe opened this issue 4 years ago • 3 comments

Strange error on OSX (catalina) using the twitter api example [here] (https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/master/Filtered-Stream/filtered_stream.js) The first time I run the script, things work as expected. After quitting (via Ctrl-C) and restarting, I get the error below. After waiting a few minutes, it works again. I'm guessing the port (or some resource) is not being fully closed on exit ?

~/git/ecobot/node_modules/needle/lib/needle.js:460
      return callback(err, resp, resp ? resp.body : undefined);
             ^

TypeError: callback is not a function
    at done (~/git/ecobot/node_modules/needle/lib/needle.js:460:14)
    at PassThrough.<anonymous> (/~/git/ecobot/node_modules/needle/lib/needle.js:711:9)
    at PassThrough.emit (events.js:321:20)
    at endReadableNT (_stream_readable.js:1220:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

dhowe avatar Aug 15 '20 07:08 dhowe

I can confirm that it's not limited to OSX as I tried the same example with Node 14 on Debian, with and without Docker image.

yuuuusha avatar Sep 27 '20 00:09 yuuuusha

Any solution to this ?

meetyourdev avatar Oct 08 '20 13:10 meetyourdev

https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/master/Filtered-Stream/filtered_stream.js#L85-L89 is running

needle.get(streamURL, {
    headers: { 
        Authorization: `Bearer ${token}`
    }
}, {
    timeout: 20000
});

According to https://github.com/tomas/needle#request-options, both headers and timeout go in the same options object. When an options object is passed to needle.get, the third argument is expected to be a function (see needle.get(url[, options][, callback]) on https://github.com/tomas/needle#needlegeturl-options-callback).

I used to see this error every couple days, changed it to the following two weeks ago, and haven't seen it since:

needle.get(streamURL, {
    headers: { 
        Authorization: `Bearer ${token}`
    },
    timeout: 20000
});

Opened https://github.com/twitterdev/Twitter-API-v2-sample-code/pull/8 to add that change.

bradslaughter avatar Oct 10 '20 17:10 bradslaughter