🚦To Return or to Discard
**Now, I'll be posting a series of summaries based on the above surveys.
The coolest indicator in this survey is that 36% of respondents would like to return errors, but instead discard them.
Most often, this is due to the fact that in their language, it's common to discard errors, but people understand that the "standard" is not always the "right way".
Also, in the comments to this post, @highloadzone and I (thank you very much for the discussion) had a massive discussion on the topic of errors and traces, which I recommend reading.
There, I came to the following thought:
Real "errors" are those that we allow to bring down our application, and they should be discarded.
And all other "errors" should be considered as "failures" or "non-successes", and they should be returned.
If you follow this path, you'll get the best of both worlds:
- Dangerous errors will be caught at the top of the stack and will have the right to even bring down the application;
- And "failures", which are syntactically convenient to express in the form of an Error structure, will always be returned from functions, because we'll have to process this failure in some way 1 or more times.
I realized that the topic is extremely large, so I'll dedicate a separate section to it in the FOP book, where I'll talk about the principles laid down by Rob Pike in the design of Go, error handling in functional languages, the problems of hidden control flow, and Railway Oriented Programming.