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

Add line numbers to parse errors #134

Open
darronschall opened this issue Jul 28, 2010 · 2 comments
Open

Add line numbers to parse errors #134

darronschall opened this issue Jul 28, 2010 · 2 comments
Labels

Comments

@darronschall
Copy link
Contributor

Originally filed by Touvan on 2010-02-17T21:42:37

What steps will reproduce the problem?

  1. If you parse a manually create JSON file, it does not give you a line error
    for the error in the error text.

You can get the line number using something like this:

try {
JSON.decode(rawJSONString);
}
catch (e:JSONParseError) {
String(rawJSONString).substring(0, e.location).split("\n").length
}

It would be nicer if it was already included in the error text.

I'd be happy to make a patch if you are interested (I assume I'd have to patch
the tokenizer.parseError() lines in JSONDecoder.as ..)

@darronschall
Copy link
Contributor Author

Updated by Touvan on 2010-02-17T21:54:32

oh, or maybe JSONTokenizer.as

@darronschall
Copy link
Contributor Author

Updated by Touvan on 2010-03-03T19:35:51

I did this in JSONTokenizer, though I'm sure a property with the line number and a way to append it in the
parseError (where the rest of the message is constructed) call would be more appropriate. This worked for my
needs though.

public function parseError( message:String ):void {
throw new JSONParseError(
message + " (line " + jsonString.substring(0, loc).split("\n").length +")",
loc, jsonString
);
}

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

No branches or pull requests

1 participant