logoalt Hacker News

oncallthrowlast Sunday at 9:05 PM4 repliesview on HN

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).


Replies

spionlast Monday at 12:45 AM

I 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/

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.

show 1 reply
jiehonglast Sunday at 10:28 PM

For 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

hu3last Monday at 12:22 AM

It's about incentives. Go makes it explicit.

And because it's standardised, it's easy to create tooling to flag mishandled errors.

morshu9001last Sunday at 10:05 PM

I'd rather have exceptions so this is done for you. Not really an option in Rust due to overhead ofc.