# Idioms for error handling with contextual information?

**URL:** <https://ziggit.dev/t/idioms-for-error-handling-with-contextual-information/11118>\
**Category:** Help\
**Tags:** language\
**Created:** [July 22, 2025, 5:01am UTC](https://ziggit.dev/t/idioms-for-error-handling-with-contextual-information/11118 "2025-07-22T05:01:29Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![squeek502](https://ziggit.dev/user_avatar/ziggit.dev/squeek502/32/409_2.png) [@squeek502](https://ziggit.dev/u/squeek502)\
**Post date:** [July 22, 2025, 5:33am UTC](https://ziggit.dev/t/idioms-for-error-handling-with-contextual-information/11118/3 "2025-07-22T05:33:45Z")

</div>

Previously:

> [@Newbie: idiom to add information to error](https://ziggit.dev/t/newbie-idiom-to-add-information-to-error/10214/5):
>
> This is commonly referred to as the “Diagnostics” pattern. There are several examples in Zig’s stdlib. Here’s one for std.json: [std.json.Diagnostics](https://ziglang.org/documentation/master/std/#std.json.Diagnostics).

> [@Example using diagnostics for error handling with std.json](https://ziggit.dev/t/example-using-diagnostics-for-error-handling-with-std-json/7882):
>
> I can’t seem to find an example of using diagnostics to report error details. For example, I have this code that fails with a SyntaxError, but which line? const std = @import("std"); const Place = struct { lat: f32, long: f32 }; test "json parse" { const parsed = try std.json.parseFromSlice( Place, std.testing.allocator, \\{ \\ "lat": 40.684540, \\ "long": -74.401422, \\} , .{}, ); defer parsed.deinit(); const pla…

---

_[View the full topic](https://ziggit.dev/t/idioms-for-error-handling-with-contextual-information/11118)._
