3 ms·
There is a difference between Go and Rust on the error ha sling front. In Go, the error handling is forced to be so verbose that adding a little bit of context
by tsimionescu 1y ago
There is a difference between Go and Rust on the error ha sling front.
In Go, the error handling is forced to be so verbose that adding a little bit of context doesn't significantly increase code size/effort, so programmers tend to actually add that context. Also, there is a very simple function for adding context to errors in the stdlib itself, fmt.Errorf.
In contrast, the difference in Rust between just returning an error (a ? at the end of the expression that can return one) vs adding context is much higher. Especially so since the standard library doesn't offer any kind of error context, so you either have to roll your own or use some error handling crate (apparently anyhow is very popular).
So, while at the language level there is little difference, the ecosystem and "incentives" are quite different.
- dllthomas 1y ago> the difference in Rust between just returning an error (a ? at the end of the expression that can return one) vs adding context is much higher I don't disagree with what you've said, but I think this is likely to be read too strongly. Adding a map_err before the ? is only a big step up in verbosity because the ? alone is so very terse.
- tough 1y agoanyhow and thisiserror are my rust error lib defaults nowadays