|
|
|
|
|
by _vvhw
1998 days ago
|
|
Thanks for the link to that proposal. Just thinking out loud, given Zig's errors primarily allow the compiler to enforce that errors are handled, and exhaustively, beyond that why can't error payloads just be passed as an input argument pointer to the function call? Maybe this is a dumb idea, but it's what C programs already do, except C programs don't have the safety of compiler checked errors offered by Zig. Does the Zig compiler need to check error payloads beyond the type system already provided? I'm not sure. I agree with you that having such a super-ergonomic error handling system will direct most code towards a certain style, but I don't think this is contrary to Zig's goals of perfect software or simplicity. It's already such a huge win on top of C's error handling. |
|
Yeah, that's definitely a reasonable way to do it, and actually Andrew gives an example of this:
https://github.com/ziglang/zig/issues/2647#issuecomment-5898...
(Andrew's example is slightly different in that rather than an explicit argument, it's an optional field in one of the arguments.)
So it's definitely not like crazy bad or anything, but also definitely less ergonomic than if you could directly return a payload with the error, and this is enough friction that it feels like you'll end up not having error information when you want it (both as an API consumer and eventually as an end-user looking at an error message).
But, I'm still very new to Zig, so perhaps my instincts on that are wrong. :-)