koajs / koa-hbs

Handlebars templates for Koa.js
MIT License
160 stars 43 forks source link

Yield added to Generator Function Causes RangeError: stack size exceeded #35

Closed dschinkel closed 9 years ago

dschinkel commented 9 years ago

I am trying to get back the response so that I can check it in my unit tests.

Once I added yield, it blew up. I'm using koa-controller as well.

module.exports = {
    find: function *(){
        var response = this;
        response.statusCode = 200;
        var foundData = null;

        //_gateway.find(function(foundData){
            if(!foundData || Object.keys(foundData).length === 0){
                response.body = null;
                response.statusCode = 204;
            }

            response.body = foundData;
            yield response;
        //});
    }
};

error:

RangeError: Maximum call stack size exceeded at Object.objectToPromise (/node_modules/co/index.js:166:25)

Now if I change yield to yield { message: "test this" }; it's fine. So I wonder if it's because of the underlying source code of koa-controller middleware that's passing back the this koa context and when I try to yield it something funky is going on because koa-controller is probably doing other things in code.

dschinkel commented 9 years ago

solved it by cloning and returning: yield Object.create(response);

jwilm commented 9 years ago

Hi @dschinkel! Did you file this in the correct repository? koa-hbs (this project) pretty much only has render() which can be yielded, and I don't see that in your code.

Let me know if there's anything I can help with :smile:

dschinkel commented 9 years ago

crap how the hell did I get in this repo. Too many tabs open sorry. Yea it was meant for koa-co.

I ended up cloning the response and yielding that.

On Sep 3, 2015, at 11:18 AM, Joe Wilm notifications@github.com wrote:

Hi @dschinkel https://github.com/dschinkel! Did you file this in the correct repository? koa-hbs (this project) pretty much only has render() which can be yielded, and I don't see that in your code.

Let me know if there's anything I can help with

— Reply to this email directly or view it on GitHub https://github.com/jwilm/koa-hbs/issues/35#issuecomment-137500609.