-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Unhelpful parse error in decoder.py #127339
Comments
Related: #121479 |
This is a feature, and as far as I know, it's been rejected previously. I think there was a DPO thread somewhere. cc @nineteendo, who had a venture with this. Maybe it's time to revisit it? |
Well, yeah I would like to revisit this in January. The idea is raising a subclass of SyntaxError: Traceback (most recent call last):
File "<stdin>", line 1, column 1
### A comment here
^
jsonyx.JSONSyntaxError: Expecting value But some adjustments are necessary, which is why this needs to be discussed. Traceback (most recent call last):
File "<stdin>", line 1, column 1-18
// A comment here
^^^^^^^^^^^^^^^^^
jsonyx.JSONSyntaxError: Comments are not allowed In the meantime, you can take a look at https://pypi.org/project/jsonyx (it can parse these comments, if you opt-in). |
Thanks: I might add - this is exactly the reason I really dislike working with python - in general. In this case, I know :
What I don't know is the general issue - namely: the decoder encounter malformed JSON, or what the offending JSON might be. Since this message comes deep into stack trace, I didn't even realize this was a result of a file parse, until I debugged it. Not being a python guy, I wasted a frustrating hour learning how to launch the same command in a python debugger, learning how to set breakpoints, learning how to display locals, etc, etc. just to discover that my problem was an invalid JSON file that was trying to be parsed. Imagine how much time a non techie person is going to waste on this ! NONE - it doesn't work, this package is broke, let's try something else. Instead of Hmm, It looks like there some kind of problem in XXX file, where a properly formed JSON is expected, but instead it encounters "#### COMMENT string" - Oh, I recognize that, comment string; I just edited that, and added the comment, so that I knew what I was doing - how weird that a JSON parser doesn't respect decades long tradition of how to make a comment line. I guess I have to correct that ! Until almost human error messages are produced your python utility - useful as it might be - is going to be hated by all , and rightly so. Error messages are for humans - emit them for humans ! |
Generally, it's a bad idea to complain about a language when you're talking to the people who maintain it :) Anyways, I don't really agree with the current message being hard to debug or recognize. I'm not sure where you got the idea that a |
It doesn't tell you which JSON file is wrong though, which is very important information if you're parsing many files. Also, if one of my users shows me this error with addition of the filename, I still can't tell them what's wrong. I need to ask them to send me the file to check the line in order to tell them how they can fix it. If we included the offending line in the error message, it would make helping people on e.g. StackOverflow easier. |
Bug report
Bug description:
This is the essentially useless output from attempting to parse a malformed json :
In my case the json file - written by hand - looked something like this:
As you can see, the first line is invalid JSON, since, for reasons left to be imagined, the designers of JSON didn't like long existing UNIX standard comment indicators.
I suspect a more usefull error message when parsing might be something like :
json.decoder.JSONDecodeError: Invalid JSON "### A comment here" , Expecting value: line 1 column 1 (char 0)
This at least gives someone NOT INTERESTED in opening a debugger - i.e. a naive and casual user - a hint that the JSON is malformed - somehow.
CPython versions tested on:
3.10
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: