Thursday, April 22, 2010

Fab.js: Two Steps Back

‹prev | My Chain | next›

Having played with it a bit last night and reading through the JSConf slides (highly recommended) today, I have the very beginnings of an inkling of what fab.js is all about.

First up, let's see if a pull resolves last night's issue in the fab.nodejs.http function. I undo my local changes (deleted some code that was failing), then I pull in the new stuff:
cstrom@whitefall:~/repos/fab$ git co index.js
cstrom@whitefall:~/repos/fab$ gl
remote: Counting objects: 46, done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 41 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (41/41), done.
From git://github.com/jed/fab
df711aa..a1039a0 master -> origin/master
Updating df711aa..a1039a0
...
(amazing how much has changed since just yesterday!)

Again, I run my all CouchDB databases play server:
cstrom@whitefall:~/repos/fab$ node ./play/all_dbs.js 
OK good sign that it hasn't crashed. When I access the /all_dbs resource, I get:
cstrom@whitefall:~/repos/fab$ curl localhost:4011/all_dbs
curl: (52) Empty reply from server
Ugh.

Checking out the server, I find:
cstrom@whitefall:~/repos/fab$ node ./play/all_dbs.js
Warning: ClientRequest.prototype.close has been renamed to end()
ReferenceError: back is not defined
at ClientRequest.<anonymous> (/home/cstrom/repos/fab/apps/fab.nodejs.http.js:24:30)
at HTTPParser.onIncoming (http:650:20)
at HTTPParser.onHeadersComplete (http:84:14)
at Client.ondata (http:601:30)
at IOWatcher.callback (net:307:31)
at node.js:748:9
Gah! That's the same error that I got last night. Jed had indicated that this was fixed in HEAD, but it looks like all that refactoring reintroduced it. No matter, I replace the back with out (and the closing close with an end to eliminate a deprecation warning):
        .addListener( "response", function( response ) {
out({
status: response.statusCode,
headers: response.headers
});

response
.addListener( "data", function( chunk ) {
out({ body: chunk });
})
.addListener( "end", out )
.setBodyEncoding( "utf8" );
})
.end();
Now my code is working again:
cstrom@whitefall:~/repos/fab$ curl localhost:4011/all_dbs
["eee","test","seed"]
I do notice something odd that I cannot quite track down: the third time I access this resource, I get a failure:
cstrom@whitefall:~/repos/fab$ curl localhost:4011/all_dbs
["eee","test","seed"]
cstrom@whitefall:~/repos/fab$ curl localhost:4011/all_dbs
["eee","test","seed"]
cstrom@whitefall:~/repos/fab$ curl localhost:4011/all_dbs
curl: (52) Empty reply from server
Checking the stacktrace, I find:
cstrom@whitefall:~/repos/fab$ node ./play/all_dbs.js
TypeError: Cannot call method 'replace' of undefined
at /home/cstrom/repos/fab/apps/fab.path.js:17:37
at /home/cstrom/repos/fab/apps/fab.path.js:37:21
at Server.<anonymous> (/home/cstrom/repos/fab/apps/fab.nodejs.js:16:17)
at HTTPParser.onIncoming (http:562:10)
at HTTPParser.onHeadersComplete (http:84:14)
at Client.ondata (http:601:30)
at IOWatcher.callback (net:307:31)
at node.js:748:9
Not real sure what the problem is there, but it doesn't seem to be with my script (at least it is not included in the backtrace). I investigate a bit longer, but I will leave that for another day.

Day #81

3 comments:

  1. Chris,

    Sorry about the regression there, I've fixed it again. I spent yesterday dividing each app into its own file for modularity, and today i'll be writing a bunch of tests. Not sure where this is failing, but I did commit a change just now that fixes an inadvertent variable shadowing.

    Stuff like this will be easier to find once we have some tests in place.

    Jed

    ReplyDelete
  2. Jed -- Thanks again! I'm not too concerned about the third-time-is-a-failure thing (at least not yet). I will give it a try tonight to see if the variable shadowing was the cause.

    Tonight I'm going to try to play with some of the other built-in apps because I am pretty sure that I still don't *really* grok all of this :)

    ReplyDelete
  3. Chris,

    Once the infrastructure stuff settles down, I'm going to be writing a bunch of apps myself. I have a whole wishlist:

    http://wiki.github.com/jed/fab/app-ideas

    ReplyDelete