Error Handling in Go (2016)
Error handling has to be one of the worst things about go. Even though IDEs can highlight where you&#x27;ve forgotten to bind an error returned from a function to a variable they don&#x27;t prompt you if you then forgot to return that err back up the call stack - it&#x27;s easy to just log the error and forget to actually return it.<p>The only way I&#x27;ve found to avoid RSI and make error handling just about tolerable is to use an IDE that supports code autocompletion - e.g. type `err` and hit tab and it should replace it with an `if err != nil {}` block. The other thing is to use pkg&#x2F;errors[1] and wrap the error so you&#x27;ve actually got a stack trace if you want to log the error further up the call chain.<p>Error handling is a solved problem - exceptions, or like the article says monads if the language is functional. The fact that Go supports neither out-of-the-box is a frustrating waste of time.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;pkg&#x2F;errors" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pkg&#x2F;errors</a>