Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poor error message #36

Closed
notslang opened this issue Jan 19, 2015 · 12 comments
Closed

poor error message #36

notslang opened this issue Jan 19, 2015 · 12 comments

Comments

@notslang
Copy link

When an error occurs in a request, I get this printed out (directly after whatever error message I print for the error):

/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:36
        fn = function () { throw arg; };
                                 ^
TypeError: undefined is not a function
  at module.exports (/usrdata/web/facebook-insights-cli/node_modules/request-promise/lib/rp.js:158:9)
  at Function.CapturedTrace.fireRejectionEvent (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/captured_trace.js:214:17)
  at Promise._notifyUnhandledRejection (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:889:23)
  at Async._drainQueue (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:84:12)
  at Async._drainQueues (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:91:10)
  at Async.drainQueues (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:14:14)
  at process._tickCallback (node.js:419:13)

...which isn't very helpful.

@analog-nico
Copy link
Member

Good find. Thanks!

Could you give me some example code so I can write a test for it?

@analog-nico
Copy link
Member

Don't mind. I found it. Two tests are already failing when executed with the latest version of Bluebird.

I will release a fix shortly.

@analog-nico
Copy link
Member

What you actually observe is the aftermath of a possibly unhandled rejection. This is a bug in request-promise, however, you probably should handle those rejections.

If you just use:

rp(...).then(function (body) { ... });

...you should also use a catch like this:

rp(...)
    .then(function (body) { ... })
    .catch(function (reason) { ... });

The catch function will handle any rejection and you won't run into the bug anymore.

@notslang
Copy link
Author

I was actually getting that output even if I was using .catch to handle the error.

@analog-nico
Copy link
Member

Oh, that is bad! Can you give me some example code so I can fix that more quickly?

@notslang
Copy link
Author

It was just:

request.get(
  uri: url
  qs: queryString
).then((body) ->
  JSON.parse(body).data
).catch((err) ->
  console.error err
)

...I would give more context, but the project is a mess right now because I'm just experimenting with the facebook API, and it should be a pretty standard call.

@analog-nico
Copy link
Member

Unfortunately, I can't reproduce the error when catch is used.
Could you give me the output of console.dir( uri: url, qs: queryString )?

analog-nico added a commit that referenced this issue Jan 19, 2015
analog-nico added a commit that referenced this issue Jan 19, 2015
@analog-nico
Copy link
Member

Hey @slang800 I just published request-promise@0.3.3 to npm.
Could you do me a huge favor and test if you now get good error messages in all of your cases? Thanks!

@analog-nico
Copy link
Member

Hi @slang800 since I wasn't able to reproduce all your issues it would be awesome if you could check whether some issues still remain with the latest version. Thanks!

@notslang
Copy link
Author

Sure. I temporarily removed request-promise & just used request wrapped by when.JS, but I'll swap that out tomorrow morning & make sure it's fixed.

@notslang
Copy link
Author

Ok, I tested it out and it seems to work! thanks!

@analog-nico
Copy link
Member

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants