2 ms·
> Are libraries typically designed to accept an optional input to store potential errors? Yes. Stdlib's JSON module has a separate diagnostics object [1]. IMO,
by maleldil 1y ago
> Are libraries typically designed to accept an optional input to store potential errors?
Yes. Stdlib's JSON module has a separate diagnostics object [1]. IMO, this is the weakest part of Zig's error handling story, although the reasons for this are understandable.
[1] https://ziglang.org/documentation/master/std/#std.json.Scanner.Diagnostics https://ziglang.org/documentation/master/std/#std.json.Scann...
- AndyKelley 1y agoI'd like to note that std.json, as it currently stands, is not a good example of proper error handling. Unless you use that awkward lower level Scanner API, if you get a schema mismatch it reports some failure code and does not populate a diagnostics struct, which is painful and useless. On the other hand the std.zon author did not make this mistake, i.e. `std.zon.parse.fromSlice` takes an optional Diagnostics struct which gives you all the information you need (including a handy format method for printing human readable messages).
- dnautics 1y agoI presume sometime in the not-immediate-but-not-too-distant-future there is going to be a push to "unify" std with a bunch of the "best practices" and call them out in the documentation.
- AndyKelley 1y agoIndeed: https://github.com/ziglang/zig/issues/1629 https://github.com/ziglang/zig/issues/1629