News for hackers. Stuff that matters.
Re:Why is Zig so Cool? by ajross on Friday November 07, 2025 @10:45PM (#45853959)
This seems kinda contrived. In practice that "ERROR DATA" tends not to exist. Unexpected errors almost never originate within the code in question. In basically all cases that "ERROR DATA" is just recapitulating the result of a system call, and the OS doesn't have any data to pass.

And even if it did, interpreting the error generally doesn't every work with a microscope over attached data. You got an error from a write. What does the data contain? The file descriptor? Not great, since you really want to know the path to the file. But even then, it turns out it doesn't really matter because what really happened was the storage filled up due to a misbehaving process somewhere else.

"Error data" is one of those conceits that sounds like a good idea but in practice is mostly just busy work. Architect your systems to fail gracefully, don't fool yourself into pretending you can "handle" errors in clever ways.

Re:Why is Zig so Cool? by skybrian on Friday November 07, 2025 @10:59PM (#45854016)
I think you've skipped over all the cases where knowing the filename is actually helpful? It's true that sometimes it isn't.

Also, a line number is often helpful, which is why compilers include it. Some JSON parsers omit that, which is annoying.

Re:Why is Zig so Cool? by ajross on Saturday November 08, 2025 @06:08AM (#45855842)
> Also, a line number is often helpful

That's not error data, that's (one level of) a stack trace. And you can do that in zig, but not by putting call stack data into error return codes.

The conflation between exception handling and error flagging (something that C++ did largely as a mistake, and that has been embraced by managed runtimes like Python or Java) is actually precisely what this feature is designed to untangle. Exception support actually turns out to have very non-trivial impact on the generated code, and there's a reason why languages like Rust and Zig don't include them.

Re:Why is Zig so Cool? by dns_snek on Saturday November 08, 2025 @08:14AM (#45856456)
[delayed]
Re:Why is Zig so Cool? by kps on Saturday November 08, 2025 @10:42AM (#45857444)
Another way to look at this example is that, for the parser, this is not an error. The parser is doing its job correctly, providing an accurate interpretation of its input, and for the parser, this is qualitatively different from something that prevents it doing its job (say, running out of memory).
Re:Why is Zig so Cool? by skybrian on Saturday November 08, 2025 @11:09AM (#45857668)
At the next level up, though, there might be code that expects to be able to read a JSON config file at a certain location, and if it fails, it’s reasonable to report which file it tried to read, the line number, and what the error was.
Re:Why is Zig so Cool? by kps on Saturday November 08, 2025 @02:44PM (#45859374)
Sure, but that's a different level with different considerations. The JSON parser shouldn't care about things like ‘files’ with ‘locations’; maybe it's running on some little esp8266 device that doesn't have such things.
Re:Why is Zig so Cool? by TylerE on Friday November 07, 2025 @10:57PM (#45854008)
Seralizing error data to text and then dumping that in a log can be pretty useful.
Re:Why is Zig so Cool? by LoganDark on Saturday November 08, 2025 @02:02AM (#45854741)
Error data should specify where the error occurred and what failed. So you'll know which file had a problem, and that the problem in question was a failure to write. From that you can make the inference that maybe the disk is full, etc.