What's the role of Diagnostics in std.zon.parse?

I tried reading the source code but couldn’t infer. Any pointers? Thanks.

Diagnostics documentation: Zig Documentation

Example usage: https://ziglang.org/documentation/0.16.0/std/#std.zon.parse.fromSliceAlloc

It collects the parsing errors, it provides an iterator over the errors and a pre made format function to dump them to a writer.

This diagnostic pattern is useful when you need/want detailed information that zigs errors don’t provide (intentionally).

std.json also uses this Diagnostics pattern, though it is a little more involved.

3 Likes

Thank you so much