←back to thread

517 points bkolobara | 1 comments | | HN request time: 0.208s | source
Show context
aeve890 ◴[] No.45042188[source]
>The code will compile just fine. The Zig compiler will generate a new number for each unique 'error.*'

This is wild. I assume there's at least the tooling to catch this kind of errors right?

replies(3): >>45042403 #>>45042586 #>>45050319 #
arwalk ◴[] No.45042586[source]
The example is a bit dubious. Sure, it compiles just fine, because the author is not using errors properly in zig. Here, he uses the global error set with `error. AccessDenid`, and as stated, it compiles just fine because when you reach the global error set, it's integers all the way down.

If the author had written `FileError.AccessDenid`, this would not have compiled, as it would be comparing with the `FileError` error set.

The global error set is pretty much never used, except when you want to allow a user to provide his own errors, so you allow the method to return `anyerror`.

replies(3): >>45042666 #>>45043035 #>>45043562 #
1. dminik ◴[] No.45043562[source]
You say never, but even the Zig stdlib does this occasionally.

Like here in `std/tar.zig`: https://github.com/ziglang/zig/blob/50edad37ba745502174e49af...

Or here in `main.zig`: https://github.com/ziglang/zig/blob/50edad37ba745502174e49af...

And in a bunch of other places: https://github.com/search?q=repo%3Aziglang%2Fzig+%22%3D%3D+e...