News for hackers. Stuff that matters.
Re:Declined Proposal: A built-in Go error check function, “try” by icebraining on Wednesday July 17, 2019 @04:26AM (#20457552)
> `if err != nil { return err }` is actually bad Go code, and not often written by good Go programmers.

Like the people who wrote the Go stdlib? Because that's filled with those - just look at the net/* packages.

Re:Declined Proposal: A built-in Go error check function, “try” by sagichmal on Wednesday July 17, 2019 @03:05PM (#20462917)
One distinction that is often made by core team members is that you only need to annotate errors at package boundaries, and that returning unannotated errors within a package is fine. But in most code, the packages are not so well-defined, or well-thought-out, or sacrosanct, that they represent a good proxy for annotation decisions.

I would much rather have an error with too much or duplicate annotation than one with not enough. And I would further argue that, yes, in the stdlib, errors are generally under-annotated.

Re:Declined Proposal: A built-in Go error check function, “try” by steev on Wednesday July 17, 2019 @06:22AM (#20457996)
Legitimate question: then what does good Go code that is written by good Go programmers do/look like? Wrap `err` in `errors.New("some function failed", err)`?
Re:Declined Proposal: A built-in Go error check function, “try” by sagichmal on Wednesday July 17, 2019 @03:10PM (#20462961)
At a minimum, an error should be logged with appropriate context and execution allowed to continue; or annotated and returned. Error annotation is currently best achieved with pkg/errors as e.g. `errors.Wrap(err, "error doing thing")`. (The xerrors suggestion of `fmt.Errorf("error doing thing: %w", err)` is awkward and hacky.)

Many programs can benefit from a more structured approach to error management. But once you get past the minimum (above) there's no one-size solution for what "a more structured approach" looks like. I really enjoy how upspin.io does their errors package, though it is somewhat esoteric. I'm also reading and generally liking how Cockroach does things, though I don't like the coupling to Protobufs.

Re:Declined Proposal: A built-in Go error check function, “try” by mikeschinkel on Thursday July 18, 2019 @05:50PM (#20474245)
Recently the Go team introduced the xerrors package for improved error management: https://godoc.org/golang.org/x/xerrors

So using these functions is becoming part of what good Go programmers do.

Re:Declined Proposal: A built-in Go error check function, “try” by qwsxyh on Wednesday July 17, 2019 @08:03AM (#20458491)
That statement is still correct even in the context of the stdlib.