Re:Go’ing Insane: Endless Error Handling
by simiones on Tuesday September 14, 2021 @06:53AM
(#28522795)
It would be interesting if anyone used error types in Go, but you'll be hard pressed to find libraries that do. return fmt.Errorf() all the way.
[ Parent
| on HN ]
Re:Go’ing Insane: Endless Error Handling
by noisem4ker on Tuesday September 14, 2021 @07:31AM
(#28523105)
In my experience, errors returned by the standard library and recent third party packages are fairly well discernible, although not in all cases.
Note that you don't need custom error types, just exported Error instances. These were in use even before wrapping was introduced with Go 1.13 (2019); one had to compare or type-assert directly instead of unwrapping.
You can use %w in fmt.Errorf to accomplish this.
Re:Go’ing Insane: Endless Error Handling
by simiones on Tuesday September 14, 2021 @10:21AM
(#28525241)
Not really. If the original error is `fmt.Errorf("divide by 0")`, no amount of `fmt.Errorf("failed to divide: %w")` will help anyone programmatically recognize the error.
Yup, fair point, I thought we were talking about libraries replacing errors to obscure the original, which absolutely happens. Lots of libraries (e.g aws-sdk) do use typed errors, so wrapping them correctly for smaller libraries that compose them is important.