flatiron/broadway — Issue #17: app.init breaks when using multiple plugins
Author: jesusabdullah
Created: 2012-01-26 01:11:57+00:00
State: open

So I was trying to write some stuff in broadway and I ran across this problem:

```js
var broadway = require('broadway'),
app = new broadway.App;

// First, use a middleware that has a significant init stage.
app.use({
attach: function (opts) {
this.place = 'rackspace';
},

init: function (cb) {
var self = this;

// You actually get the same error if you drop the nextTick, but I wanted this to be truly async.
process.nextTick(function () {
self.letsGo = function () {
console.log('Let\'s go to '+place+'!');
}

cb();
});
}
});

// Second, try to add another plugin. It doesn't even have to *do* anything.
app.use({
attach: function () {}
});

// When initializing, app.letsGo should get defined (by my understanding)
app.init(function (err) {
if (err) {
throw err;
}

// app.letsGo is undefined
app.letsGo();

});
```

The corresponding stack trace from broadway looks like:

```
{
"process": {
"pid": 6807,
"uid": 1000,
"gid": 1000,
"cwd": "/tmp/test",
"execPath": "/usr/local/bin/node",
"version": "v0.6.6",
"argv": [
"node",
"/tmp/test/test.js"
],
"memoryUsage": {
"rss": 14753792,
"heapTotal": 8667776,
"heapUsed": 4865800
}
},
"os": {
"loadavg": [
0.1015625,
0.15185546875,
0.1416015625
],
"uptime": 18717.25650203
},
"trace": [
{
"column": 7,
"file": "/tmp/test/test.js",
"function": null,
"line": 30,
"method": null,
"native": false
},
{
"column": 5,
"file": "/tmp/test/node_modules/broadway/lib/broadway/app.js",
"function": "onComplete",
"line": 86,
"method": null,
"native": false
},
{
"column": 10,
"file": "/tmp/test/node_modules/broadway/lib/broadway/features/index.js",
"function": "Object.ensure",
"line": 10,
"method": "ensure",
"native": false
},
{
"column": 18,
"file": "/tmp/test/node_modules/broadway/lib/broadway/app.js",
"function": "ensureFeatures",
"line": 92,
"method": null,
"native": false
},
{
"column": 25,
"file": "/tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js",
"function": null,
"line": 105,
"method": null,
"native": false
},
{
"column": 5,
"file": "/tmp/test/node_modules/broadway/lib/broadway/app.js",
"function": "initPlugin",
"line": 108,
"method": null,
"native": false
},
{
"column": 13,
"file": "/tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js",
"function": null,
"line": 97,
"method": null,
"native": false
},
{
"column": null,
"file": null,
"function": "Array.forEach",
"line": null,
"method": "forEach",
"native": true
},
{
"column": 24,
"file": "/tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js",
"function": null,
"line": 26,
"method": null,
"native": false
},
{
"column": 9,
"file": "/tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js",
"function": "Object.forEach",
"line": 96,
"method": "forEach",
"native": false
}
],
"stack": [
"TypeError: Object [object Object] has no method 'letsGo'",
" at /tmp/test/test.js:30:7",
" at onComplete (/tmp/test/node_modules/broadway/lib/broadway/app.js:86:5)",
" at Object.ensure (/tmp/test/node_modules/broadway/lib/broadway/features/index.js:10:10)",
" at ensureFeatures (/tmp/test/node_modules/broadway/lib/broadway/app.js:92:18)",
" at /tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js:105:25",
" at initPlugin (/tmp/test/node_modules/broadway/lib/broadway/app.js:108:5)",
" at /tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js:97:13",
" at Array.forEach (native)",
" at /tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js:26:24",
" at Object.forEach (/tmp/test/node_modules/broadway/node_modules/utile/node_modules/async/lib/async.js:96:9)"
],
"level": "error",
"message": "uncaughtException"
}
```

I'm going to dig into the code now that I have this stack trace (the one I saw when I discovered this with vows was less detailed) but I have a feeling I'm out of my element here.