-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Zig Version
0.11.0
Steps to Reproduce and Observed Output
Usually when std.json fails to parse some json data, it panics and produces an error log something like this:
error: UnknownField
/usr/local/lib/zig/std/json/static.zig:371:25: 0x1061e741c in innerParse__anon_11603 (dev)
return error.UnknownField;
^
/usr/local/lib/zig/std/json/static.zig:467:64: 0x1061d3744 in innerParse__anon_11227 (dev)
arraylist.appendAssumeCapacity(try innerParse(ptrInfo.child, allocator, source, options));
^
/usr/local/lib/zig/std/json/static.zig:140:19: 0x1061b5a35 in parseFromTokenSourceLeaky__anon_10125 (dev)
const value = try innerParse(T, allocator, scanner_or_reader, resolved_options);
^
/usr/local/lib/zig/std/json/static.zig:107:20: 0x10618e04d in parseFromTokenSource__anon_7661 (dev)
parsed.value = try parseFromTokenSourceLeaky(T, parsed.arena.allocator(), scanner_or_reader, options);
^
/usr/local/lib/zig/std/json/static.zig:73:5: 0x106187a2d in parseFromSlice__anon_6948 (dev)
return parseFromTokenSource(T, allocator, &scanner, options);
^
/Users/Robert/zig/dev/src/tiles.zig:35:18: 0x106186e3e in loadTiles (dev)
const data = try json.parseFromSlice([]TileRecord, a, string, .{});
^
/Users/Robert/zig/dev/src/state.zig:21:22: 0x10618815e in init (dev)
.tiles = try tile.loadTiles(a, textures),
^
or
error: UnexpectedToken
etc...
This is not helpful at all in debugging which part of the json failed to parse and why.
Expected Output
It would be great if std.json would log the line of json it failed to parse, and why it couldn't be parsed into the given struct
For example
ERROR: failed to parse json string
{"amount": 1.10, "name": "foo"}
into
struct {amount: u32, name: []u8,};
Expected identifier "amount" to hold u32, found f32.
#etc...
VisenDev, lxn, emilioplatzer, boisgera, timsavage and 10 morethejoshwolfe and lipfangmoe
Metadata
Metadata
Assignees
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.