Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

I can't get node-codein to work. #3

Closed
trusktr opened this Issue · 21 comments

4 participants

Joseph Orbegoso Pea Silviu Marian Filip Weiss frantzmiccoli
Joseph Orbegoso Pea

I can't get node-codein to work.

My app is a locomotive app (locomotivejs.org) and I'm putting the require for node-codein inside config/environments/all.js (the main configuration file for locomotive apps).

var codein = require('node-codein');

Then when I visit http://localhost:55281/ in Chrome, the interface shows up, but if I type "global" and press enter I get an error saying "TypeError: Cannot read property 'accept' of undefined".

If I try console.log(global) nothing is logged. I'm guessing there should be an expandable tree that shows the contents of the global object?

Perhaps I must place the require() statement somewhere else with repsect to a Locomotive app?

EDIT: Nope, that doesn't work. I tried requiring node-condein at the root of the locomotive's lcm command but the results are the same.

Also, after attempting to enter global and pressing enter then refreshing the page, I'll briefly see the message "Bad response from server (0)".

Silviu Marian
Owner

What browser and version are you using?

Joseph Orbegoso Pea
Silviu Marian
Owner

can't reproduce. can you upload a basic setup somewhere?

Filip Weiss

Same problem here.

global.varname works
but just global gives me "TypeError: Cannot read property 'accept' of undefined" on the Server-Side

Silviu Marian
Owner

I can't reproduce this.

There is no "accept" property nor field anywhere in this project. I've ran a grep to confirm.
Latest node, latest lcm, latest everything. "global" in console runs clean.

Just zip the project folder and put it somewhere, I'll have a look.

frantzmiccoli
Collaborator

Hello,

I've reproduced the problem, it's linked with express.

package.json:

{
    "name": "Node-codein_bug",
    "description": "",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "express": "3.0.1",
        "node-codein": "1.0.2"
    }
}

app.js :

require("node-codein");

// the following is express' helloworld
var express = require('express');
var app = express();

app.get('/hello.txt', function(req, res){
  var body = 'Hello World';
  res.setHeader('Content-Type', 'text/plain');
  res.setHeader('Content-Length', body.length);
  res.end(body);
});
frantzmiccoli
Collaborator

The problem is inside the stringify call, I'm trying to make a descent fix on it. I'll try to send a pull request today.

Silviu Marian
Owner

I don't believe a simple encoding function can be the problem
You can fit dozens of try-catch clauses in there and anywhere else and it won't fix anything. See

process.on('uncaughtException', function(e){ console.log(e.stack); });

reveals an implementation of http.IncomingMessage which isn't documented anywhere but it seems to override the regular event chain for requests (q). I think that before its kicks in, we already sent a response and both connections are gone.

If you look at (libs/request.js) in express all those shorthand functions have no built-in validation whatsoever. Probably they thought that whoever's going to use express won't be using node's regular HTTP servers anymore

Silviu Marian ketamynx referenced this issue in visionmedia/express
Closed

Express doesn't work with node-codein #1439

frantzmiccoli
Collaborator

Nice try, but I've fixed a bunch of errors in the express files and then, I ended up in the dependencies. The problem il linked with strinfigy and I've fixed it. Since it'll be my first pull request on GitHub it might take a moment before I figure how to do it.

Silviu Marian
Owner

I'm dying to see it. :+1:

Silviu Marian
Owner

It's a simple fork/pull operation. Click "Fork", apply the patches, click Pull Request. (on this page)

frantzmiccoli
Collaborator

#5 Sorry, I didn't know how to attach the code to this ticket.

Silviu Marian
Owner

I still don't fully understand what happened. So you're basically saying that JSON.stringify can't enumerate object's functions that don't run on their own?

frantzmiccoli
Collaborator

No, it's not that.

When you stringify an object it considers function, properties but also the getters defined on the object (look at the pull request above to see an example). The problem rose when the getter code rose error, in that case, even if you know that "myProperty" exists within "myObject" the simple call to "myObject["myProperty"] can raise an error. That case was not handle in stringify.

Silviu Marian
Owner

So this only applies to getters? I'm only wondering if there's any other scenarios I might've actually missed with the encoding function.

frantzmiccoli
Collaborator

It's not you, it's basically a problem (bug ?) of JSON.stringify. I'm not sure you're supposed to handle any special case (other than circular).

Silviu Marian
Owner

Well. Closing it up then. Thanks again for all your help, that's a great job right there.

frantzmiccoli
Collaborator

Your project is great, it's a pleasure to have an opportunity to improve it. Douglas Crockford refused my pull request under the global idea "that buggy code should raise crash".

Silviu Marian
Owner

Thank you. Well, he actually made it quite clear; normally consoles/debuggers are highly weaved in within their platforms, they don't exist as hand-crafted external packages. And personally I don't see any other fail cases, except for this project.

Nevertheless, I posted a link to you on the readme.md under changelog. If that's not your website let me know and I'll change it.

By the way, do you have any approach as to how this console can gain some access to local variables and private scopes? Just asking...

frantzmiccoli
Collaborator

That's mine, thank you ! I appreciate the attention.

I've tried to look around your problem and tested some hacks, I think that this is not possible because that would require native functions to do introspection, and there's no such functions as far as I've read about that topic.

Joseph Orbegoso Pea

Sweet. Can't wait to test the changes. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.