News for hackers. Stuff that matters.
Re:Why is Zig so Cool? by smj-edison on Saturday November 08, 2025 @02:04PM (#45859059)
Genuine question, how would error set unioning work with payloads? error.WriterFailed (might be getting the exact name wrong) is returned from many different writers, whether writing to a statically allocated array, writing to a socket, or writing to a file. Each error would have a very different payload, so how would you disambiguate between the different payloads with a global error type? The way I see it is either you have error sets, or payloads, but not both.
Re:Why is Zig so Cool? by weebull on Saturday November 08, 2025 @03:03PM (#45859514)
I'm also wondering what payload people want. There's already an error handling trace (similar but different to a normal stack trace) that captures the how the error propagates up to the point it's being handled so shows you exactly where the initial point was.
Re:Why is Zig so Cool? by dns_snek on Sunday November 09, 2025 @09:57AM (#45866006)
A payload can contain any details that the producer of that error believes are important. I don't know what you mean by the error handling trace, how does that help with the toy JSON parsing example? I want the payload to indicate the position in the input string where the parser encountered an error.

I want a function like `diffFiles(path_a, path_b)` to have an error set of `error { ReadError }` with more detailed information in the payload (e.g. file path, translated error code). The alternative is: `error { FileAReadErrorNotFound, FileBReadErrorNotFound, FileAReadErrorPermissionDenied, FileBReadErrorPermissionDenied, ...}`

Re:Why is Zig so Cool? by dns_snek on Sunday November 09, 2025 @09:34AM (#45865860)
I would expect a generic interface to define a base error payload which would contain some common information and a pointer to the implementation-specific details (or embed them in the original payload as a tagged union).