logoalt Hacker News

veggierolllast Tuesday at 5:39 PM3 repliesview on HN

Error handling is one of my favorite parts of Go. The haters can rip `if err != nil { return fmt.Errorf("error doing thing: %w", err) }` from my cold dead hands.


Replies

catlifeonmarslast Wednesday at 2:39 AM

How do you feel about

    v, err := foo.Open()
    // …
    defer func() {
        if closeErr := v.Close(); closeErr != nil {
            err = fmt.Errorf("while closing %w: %v", err, closeErr)
        }
    }() 
  
    // …

When you’re writing something trivial/pure, Go’s error handling is fine, if maybe a tad bit verbose, but it quickly becomes nightmarish when you start to do nontrivial things that are typical for systems programming.

FWIW I love Go, it’s my daily driver for most things. I still think it can get messy far too quickly

show 1 reply
thaynelast Tuesday at 9:44 PM

Error handling is the thing I hate the most about go. And none of the serious proposals I've seen would remove your ability to continue using `if err != nil`

show 1 reply
ummonklast Tuesday at 6:22 PM

You don't use gofmt?

show 1 reply