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

Promise.coroutine() is difficult to debug #421

Closed
petehunt opened this issue Dec 30, 2014 · 6 comments
Closed

Promise.coroutine() is difficult to debug #421

petehunt opened this issue Dec 30, 2014 · 6 comments

Comments

@petehunt
Copy link
Contributor

@petehunt petehunt commented Dec 30, 2014

First of all thanks for your great work on bluebird.

The following code sample (at scale) is very difficult to debug:

var Promise = require('bluebird');

Promise.longStackTraces();

var coro = Promise.coroutine(function*() {
  yield 7;
});

coro();
[petehunt@petehunt-mbp tmp]$ node --harmony break.js
Possibly unhandled TypeError: A value was yielded that could not be treated as a promise

    See http://goo.gl/4Y4pDk

From previous event:
From previous event:
    at Object.<anonymous> (/Users/petehunt/tmp/break.js:9:1)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)
    at startup (node.js:124:16)

I understand that it's likely impossible to capture a perfect stack trace, but I spent hours tracking down this bug and was hoping to get a better error message. I took a rough pass at an improvement here: petehunt@d15a93c

Is this something worth cleaning up and trying to get in? Or is this something you'd want to do? Or is this not worth doing?

@benjamingr
Copy link
Collaborator

@benjamingr benjamingr commented Dec 30, 2014

Very awesome of you to open this issue we were just debating yesterday why people are getting TypeError: A value was yielded that could not be treated as a promise.

We take the ability to debug code very seriously. What do you think a meaningful stack trace would be here? None of the userland functions here are named.

@petehunt
Copy link
Contributor Author

@petehunt petehunt commented Dec 30, 2014

w/ my patch above on a modified test file (https://github.com/petehunt/bluebird/blob/d15a93ca57c24c8a935be35b8c62a6b2123e03a7/demo.js) I was able to get it to this (note the "from coroutine" bit):

Possibly unhandled TypeError: A value 7 was yielded that could not be treated as a promise

    See http://goo.gl/4Y4pDk

From coroutine:
    at Object.<anonymous> (/Users/petehunt/Projects/bluebird/demo.js:5:21)
From previous event:
    at /Users/petehunt/Projects/bluebird/demo.js:10:9
    at GeneratorFunctionPrototype.next (native)
From previous event:
    at /Users/petehunt/Projects/bluebird/demo.js:10:9
    at GeneratorFunctionPrototype.next (native)
From previous event:
From previous event:
    at Object.<anonymous> (/Users/petehunt/Projects/bluebird/demo.js:13:1)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)
    at startup (node.js:124:16)

This is I think about as good as we can get without using a syntax transform to capture the stack trace at the point of yielding (unless you guys have some magic for introspecting where a generator currently is at).

@petkaantonov
Copy link
Owner

@petkaantonov petkaantonov commented Dec 30, 2014

Thanks for this, as @benjamingr says debuggability is very important and we are constantly trying to find improvement in that area.

I don't see any harm in it, the coroutine function should not be called at runtime anyway so it can do expensive setup stuff.

Before pull request remove the js/browser/bluebird.js from the commit (this is only commited in release commits for a download link, I should get a real CDN)

Also call util.toString on value, before passing it to .replace, it will handle the case where value could be Object.create(null) which throws when converted to string

@benjamingr
Copy link
Collaborator

@benjamingr benjamingr commented Dec 30, 2014

It's also worth to check for performance degradation since stacks are passed here - and possibly only pass the stack along under .longStackTraces().

@spion
Copy link
Collaborator

@spion spion commented Dec 30, 2014

@benjamingr should be fine though, the stack is pre-computed only once when Promise.coroutine is called

@petehunt
Copy link
Contributor Author

@petehunt petehunt commented Jan 3, 2015

I'll try to wrap this up end of this week. Pretty crazy time right now.

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

Successfully merging a pull request may close this issue.

None yet
4 participants