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
Report row and line number when generating errors, instead of an absolute position #166
Comments
I think it would be better to add a new helper function. |
A new api that returns detailed parser/ error information as structured data instead of an error message would be fantastic - it would let me make the python yyjson wrapper truly drop-in to replace the standard library. Right now, I can't properly populate the JSONDecoderError exception because of the lack of pos. A similar issue in simdjson has been open for years. |
I've come up with a new API, let's see if it meets the needs? @CarterLi @TkTech /**
Locate the line and column number for a byte position in a string.
This can be used to get better description for error position.
@param str The input string.
@param len The byte length of the input string.
@param pos The byte position within the input string.
@param line A pointer to receive the line number, starting from 1.
@param col A pointer to receive the column number, starting from 1.
@param chr A pointer to receive the character index, starting from 0.
@return true on success, false if `str` is NULL or `pos` is out of bounds.
@note Line/column/character are calculated based on Unicode characters for
compatibility with text editors. For multi-byte UTF-8 characters,
the returned value may not directly correspond to the byte position.
*/
yyjson_api bool yyjson_locate_pos(const char *str, size_t len, size_t pos,
size_t *line, size_t *col, size_t *chr); |
I believe this checks all the boxes 👍 . I'm in Korea until the 15th and will test it in py_yyjson shortly after I return. |
I think it's good enough for position locating. I'm waiting for a new release then. Another question: we are reporting For example: fastfetch-cli/fastfetch#866 (comment) Can we report a comma is expected? |
Error messages like these could be easily improved, please create a new issue and I will address it soon. |
I found it a little bit hard to use with |
The |
Got it.
Seems not necessary IMO. |
Okay, then I won't reopen it. |
Is your feature request related to a problem? Please describe.
Currently yyjson reports
Describe the solution you'd like
Describe alternatives you've considered
Additional context
I use yyjson for parsing config files. It would be easier to find where the problem is if users can get its line and row number.
The text was updated successfully, but these errors were encountered: