-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Zig Version
0.12.0-dev.1383+7c5d01b95
Steps to Reproduce and Observed Output
Currently when parsing a json file, the only way errors are logged is thru the zig error system - which is fine for most applications - but it is not great for parsers since it makes it very unclear where the parsing failed and why. See #16936
One way to fix this would be this proposal #2647, however since this has been open for several years now, it is unlikely that any change like this will happen soon.
Alternatively an outparameter could be passed which records the location of an error in the input string. This sort of approach is very common in a lot of C codebases.
As a much simpler solution that doesn't involve any language level change would be to add a log level field to std.json.ParseOptions
which would enable logging for the progress of parsing and what exactly caused the parser to fail.
A similar example of an approach like this in the standard library would be the verbose_log
parameter of the GeneralPurposeAllocator
Config which logs when memory allocations are happening.
Expected Output
The std.json
parser would be able to log the cause and location of an error on the event that parsing fails. This would make it much easier to track down why parsing fails and make zig a more pleasant and robust language to use.
This use case comes from me doing a lot of json parsing on my personal project in zig. Debugging json parsing issues right now is not super pleasant