I finally hit a scenario where i need dynamic error messages to be shown to an end user for binary decoder i am busy with. This naturally led me to discover the diagnostics pattern, which I see has been discussed a few times on this forum. The idea made a lot of sense and I looked at some examples but they all seemed a bit.. complicated? Why not just capture text if the goal is the end user? Did an implementation that makes sense to me:
https://codeberg.org/acudac/utils-zig/src/branch/main/src/Diagnostics.zig
How i used this just now
https://codeberg.org/acudac/broto-zig/src/branch/main/src/Decoder.zig
Hitting this catch will leak the message:
aa thanks, fixed in https://codeberg.org/acudac/utils-zig/commit/554ca4e60a735194867834cf4fe52fa6536cdc32
Oh, you also want writeAll rather than write. In general, _ = usually is a mistake.
3 Likes
I think an app would want to probably capture text directly but a library would want to provide the ingredients instead. That’s my reasoning anyway.
1 Like