5 ms·
Does the Zig language not have useful exceptions/stacktraces that can be propagated out? At a high level, all non-trivial programming is composition. And (see
by twhitmore 7mo ago
Does the Zig language not have useful exceptions/stacktraces that can be propagated out?
At a high level, all non-trivial programming is composition. And (see principle of encapsulation) the vast majority of errors shouldn't be recovered and just need to be propagated out.
Then, to be useful, errors need enough information to be diagnosed or investigated. It seems like this should have been a straight-forward requirement in the language design.
- dnautics 7mo agoZig has error unions on return types which are basically a special cased (rust enum aka sum type) of the return type with a special cased (c enum aka enumerated type), and stacktraces are only available in certain build modes. A "diagnostics" pattern has emerged in the community to optionally request extra information about a failure. You can pass a pointer to the diagnostic (it can be on the stack) and get the extra info back. It's just a more explicit version of what would otherwise happen in a language with error payloads.
- Cloudef 7mo agoNote that this "diagnostics" pattern is only meant for handling a error locally with potential extra information, or showing a more useful error to a end user of the software. For software bugs, crashes, or developer facing errors, you often don't have to do anything as zig has pretty good error traces by default.
- andyferris 7mo ago> stacktraces are only available in certain build modes > zig has pretty good error traces by default These seem rather conditional. If I need to run release-fast in prod, say, do we loose these error traces (for bugs)?
- messe 7mo agoYou do, to a significant extent. Though there is always the option of running ReleaseSafe.
- Cloudef 7mo agoYou can enable error traces for release-fast builds as well, without enabling full debug info. Though the quality of call stack of course vary depending on optimization level.
- dnautics 7mo agooh awesome. I thought error traces were only on debug and optionally on ReleaseSafe.
- Zambyte 7mo ago> stacktraces are only available in certain build modes. Minor correction: stack traces are available on all build modes, but different build modes have different defaults. See: std.Options.allow_stack_tracing
- messe 7mo ago> Does the Zig language not have useful exceptions/stacktraces that can be propagated out? Yes, it has error return traces.