5

I'm working on a page and getting "Unexpected syntax error: Unexpected token c" attributed to line 1 of an empty index.

I want to double check that JSON values are valid, but what is the best way to get to the bottom of a line number for "there is a syntax error somewhere in your code, but I'm not telling where?" An approximation of a binary search, where you disable/enable narrower areas of your code and see if you can point a finger that way?

This may be a question for programmers, but I was wondering in general what to do with an error that Chrome doesn't give a useful line number for.

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
  • Such errors can come from calls to `eval()` or `new Function()` too, or from the JSON parser. – Pointy Jan 13 '14 at 21:24
  • clicking on the message can often lead to a stack, sometimes hidden as "get" in chrome, and the stack should have recognizable function names you can search for. – dandavis Jan 13 '14 at 21:25
  • Thanks. I debugged this one by logging every JSON string before parsing it, which turned up the malformed JSON it was crashing on. Now it's happy. Thanks, – Christos Hayward Jan 13 '14 at 21:29

0 Answers0