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

Cannot call method 'toString' of null #6

Open
Emmerman opened this issue Oct 1, 2010 · 4 comments
Open

Cannot call method 'toString' of null #6

Emmerman opened this issue Oct 1, 2010 · 4 comments

Comments

@Emmerman
Copy link

Emmerman commented Oct 1, 2010

http:572
  var statusLine = "HTTP/1.1 " + statusCode.toString() + " "

TypeError: Cannot call method 'toString' of null

For string 215
if (e) { return finish(null, {}) }

Maybe 404 instead null?

@yrn1
Copy link

yrn1 commented Nov 9, 2010

Seen when calling serveFile('/', 200, {}, req, res)

@vdidenko
Copy link

Cat it be an instance of the https://github.com/cloudhead/node-static/issues#issue/4 issue?

@yrn1
Copy link

yrn1 commented Mar 18, 2011

Yes, it is. The proposed fix in https://github.com/cloudhead/node-static/issues#issue/4 is also valid, but only for that case (wrong path). In general, you should never call finish(null, ...), because that will always result in the 'TypeError: Cannot call method 'toString' of null' error.

@metaleap
Copy link

metaleap commented Apr 6, 2011

Having the same issue. This generally happens if the path is not a file but a directory. Now we COULD check for this ourselves before calling serveFile(), however, that isn't the issue. This exception crashes node since it is uncaught and cannot be caught. Now say you have a live site running and it gets crawled? /files/foo/exist.txt may work fine so the crawler decides to fetch /files/foo/ , thanks to your custom /files/ handler node-static will serve this too and crash node because it is not a file.

So as I said we COULD check for this (dir or file?) ourselves but I actually tested this to see how node-static performs in case there is ANY error accessing the file. This could be wrong / changed file permissions or any other file access error. It DOES jump into my "error" listener, so far so good. I do the

resp.writeHead(500, { 'Content-Type': 'text/plain' });
resp.end(JSON.stringify(err));

thing and it gets executed. STILL what happens next is this:

http.js:832
var statusLine = 'HTTP/1.1 ' + statusCode.toString() + ' ' +
^
TypeError: Cannot call method 'toString' of null
at ServerResponse.writeHead (http.js:832:45)
at [object Object].finish (/home/foo/bar/node_modules/node-static.js:108:17)
at /home/foo/bar/node_modules/node-static.js:87:18
at /home/foo/bar/node_modules/node-static.js:215:33
at [object Object]. (/home/foo/bar/node_modules/node-static.js:245:17)
at [object Object].emit (events.js:64:17)
at afterRead (fs.js:858:12)

@cloudhead I have no problem fixing this myself for my local 0.5.3 for now but will this be fixed "officially" for 0.5.4 too? I'm sure it's just a one-line check-for-null/undefined... fingers crossed.

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

No branches or pull requests

4 participants