3 ms·
This is interestingly somewhere where Go really shines, in my experience. Go has no requirement to wrap (or, indeed, even handle at all) errors; yet, despite th
by oncallthrow 9mo ago
This is interestingly somewhere where Go really shines, in my experience. Go has no requirement to wrap (or, indeed, even handle at all) errors; yet, despite this, Go codebases I've worked in almost always perform error handling properly (wrapping at each layer of the call stack, so it's easy to identify where an error occurred).
- morshu9001 9mo agoI'd rather have exceptions so this is done for you. Not really an option in Rust due to overhead ofc.
- jiehong 9mo agoFor the flat structure part, it’s much less shiny, though. Weirdly, the last time I saw an error in production I couldn’t investigate was because of a go service with no error wrapping… funny coincidence
- hu3 9mo agoIt's about incentives. Go makes it explicit. And because it's standardised, it's easy to create tooling to flag mishandled errors.
- spion 9mo agoI don't think there is anything in Go (the language) that helps achieve this - its mostly cultural. (Go creators and community being very outspoken about handling errors). In fact, the easiest thing to do in Go is to ignore the error; the next easiest is to early-return the same error with no additional context. Technically speaking, Rust has way better tools for adding context to errors. See for example https://docs.rs/color-eyre/latest/color_eyre/ https://docs.rs/color-eyre/latest/color_eyre/ It does expect you to use `wrap_err` to get the benefits, though. Which is easier to do than what Go requires you to do for good contextual errors, and even easier if you want reasonable-looking formatting from the Go version.
- spion 9mo agoIMO you need both things: culture to make it happen, and technology to make it easy and reasonable looking. Rust lacks the former to some degree; Go lacks the later to some degree (see e.g. kustomize error formatting - everything ends up on a single line)