This (it looks like to me) is an attempt to pull in the best bits of Dave Cheney's errors package (which I love) into the standard library: <a href="https://github.com/pkg/errors" rel="nofollow">https://github.com/pkg/errors</a><p>Standardising error unwrapping is a great idea IMHO and I think that this has a lot of merit.<p>I don't like the `fmt.Errorf("more description: %w", err)` though for several reasons.<p>Firstly it is a lot more opaque than Dave Cheney's original mechanism errors.Wrap(err, "more description"). You've got to check the format string for a `%w` to see if it is wrapping an error or not.<p>Secondly why is this really important functionality in `fmt` and not in `error`?<p>And finally we've been encouraged to write `fmt.Errorf("more description: %v", err)` (note `%v` not `%w`), so I think there will be a lot of unwrapped errors.<p>...<p>I'm not sure enough has been thought about the backwards incompatibility. With rclone I try to maintain compatibility with the current go release and a few previous ones so that rclone can remain running with distro go versions and gccgo both of which are a bit behind. For something as common as error handling this will cause lots of libraries to suddenly be no longer usable with anything less than go1.13.<p>IMHO I think this would be better staying as a non standard library package for the time being while more kinks are worked out.
It seems like golang designers are totally isolated from what's been happening in the last 30 years in languages design. They still insist on their weird way of error handling just like they were stubborn for years and years on the lack of package management and eventually a very weird and rudimentary way of it. It's sad because I use this language extensively but its weirdly mediocre design is totally unfathomable. It's like they are very stubborn to do anything but the right thing.
From what I have seen, the Go 2 Error Values plan[1] has not received enough exposure to generate the level of feedback necessary to support a go/no-go decision re a major change in 1.13 -- one we cannot opt-out of, at that.<p>I suspect that the overwhelming majority of Go developers has no idea this is in the works. It was covered once on the blog last August in the Draft Design summary, when there wasn't any code behind it. It was not mentioned in Go 2 Here We Come[2], nor at the start of the below golang-dev thread. It was mentioned on golang-dev when I posted a link to the issue tracker in late January, but my posts would see a fraction of the attention vs those by Rob, Robert, Russ, Ian, et al.<p>There are outstanding issues with the current draft, specifically its performance[3] and API[4].<p>If it lands in 1.13, please give it Experimental status, with a build or env flag to disable changes to existing APIs, and perhaps a way to re-enable them on a per-function or per-package basis.<p>[1] <a href="https://github.com/golang/go/issues/29934" rel="nofollow">https://github.com/golang/go/issues/29934</a><p>[2] <a href="https://blog.golang.org/go2-here-we-come" rel="nofollow">https://blog.golang.org/go2-here-we-come</a><p>[3] <a href="https://github.com/golang/go/issues/29934#issuecomment-486503822" rel="nofollow">https://github.com/golang/go/issues/29934#issuecomment-48650...</a><p>[4] <a href="https://github.com/golang/go/issues/29934#issuecomment-483509242" rel="nofollow">https://github.com/golang/go/issues/29934#issuecomment-48350...</a><p>.<p>[Originally posted on golang-dev, in response to "Last call for feedback on Go 1.13..."]<p><a href="https://groups.google.com/d/topic/golang-dev/jPY0RYXSvCU/discussion" rel="nofollow">https://groups.google.com/d/topic/golang-dev/jPY0RYXSvCU/dis...</a>
As others have stated, this seems incredibly odd to me:<p>> If the last argument is an error and the format string ends with ": %w", ...<p>This seems like a magic-string kinda hack to me. I like the idea of wrapping errors so that you keep the stack and full context, especially since you may need additional structured data from all errors (e.g. DB error, access error, ...) to produce user facing messages, so IMHO the wrapping should be more explicit than just %w.
Speaking of errors, here's how i approach writing a good error message.<p>Fill in the blank "Well basically what happened is ___________"<p>For example i've found this has helped me to go from "Invalid phone number" to "The phone number needs to be 10 digits"
Not sure why people are bashing Go because of it's choices.<p>Looking forward to shit storm once they introduce generics in near future. I am sure people will still complain that this is not how parametric polymorphism should be implemented.
I think this is a positive development and should be cheered by Go programmers. Slowly but surely they progress on the road to implementing Exceptions. (<i>ducks and runs</i> like a scaredy cat to avoid the wrath of Go Fans)
What I'm really looking for is being able to debug any production Go binary by inspecting the stack trace behind an error. Could be gated by an environment variable.