logoalt Hacker News

9rxlast Tuesday at 8:04 PM0 repliesview on HN

Even the laziest programmer is going to want to wrap the error with another error, and usually you will want to do more than that.

You can put that in-band, with something like:

    v := funcWithError()? err := { 
        return fmt.Errorf("lazy programmer wrapping: %w", err)
    }
But in that case what have you really gained?

Or you can do some kind of magic to allow it to happen out of band:

    // found somewhere else in the codebase
    func wrapErr(err error) error {
        if err == nil {
            return nil
        }
        return fmt.Errorf("lazy programmer wrapping: %w", err)
    }

    v := funcWithError()?(wrapErr)
        
But that's where you start to see things hidden.