- When prototyping, deferring worrying about exact error types is helpful
- In applications, you aggregate so many types of errors, sometimes it is easier just to dynamically accept any.
1 - Just have a Todo(String) in your error enum while prototyping. Remove it as you clean up a prototype, and you get a nice set of compiler errors telling you everywhere that needs to change.
2 - If you're aggregating so many error types that it's unwieldy, you're probably doing to much in one place. That has all sorts of down stream issues with testability and what not. Hacking your error types to make it easier is probably not the best option.
I'd disagree. In a static-site-generator, I need to deal with
- file format errors
- syntax highlighting errors
- io errors
- Template language errors
- Adhoc errors I construct throughout the application
- Regex errors
- RSS errors
- jsonfeed errors
- sitemap errors
- git errors
Without even getting into any errors from the webserver that is being run. Yes, I could carefully construct an error enum for each subsection of the application and bubble those up ... but why? I'm not programmatically acting on these but sending them up to the user.
https://dave.cheney.net/2016/04/27/dont-just-check-errors-ha...
The entire stdlib does this. An error stack is never present from stdlib functions' errors, and third party libraries I see it just as infrequently.
If only novice go devs do that, than the entire go core team are novices, as well as the authors of popular go projects like kubernetes and docker.
It seems better to have coarse-grained types than to standardize the wrong type hierarchy?
All of that being said, modern Go (written in the past few years) could avoid these pitfalls. But very few production codebases were both written in the past few years and only use libraries written in the past few years.
I've worked on Go codebases for the past 5-6 years.
And it's not like they couldn't add better types to errors without breaking backwards compat. Returning a type that implements error instead of fmt.Errorf doesn't break existing semantics.