Code Room
Code reviewMediumcr-g321
Subject Error handlingLevel Mid–Senior~16 minCommon in Code quality & review · Algorithms & data structures interviewsIndustries Software development

Question

Review this Go function that wraps a downstream error before returning it. The caller wants to treat 'not found' differently from a real outage.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewgo
func loadUser(id string) (*User, error) {    u, err := repo.Find(id)    if err != nil {        return nil, fmt.Errorf("failed to load user %s", id)    }    return u, nil} func handler(w http.ResponseWriter, id string) {    u, err := loadUser(id)    if errors.Is(err, sql.ErrNoRows) {        http.Error(w, "no such user", 404)        return    }    if err != nil {        http.Error(w, "internal error", 500)        return    }    writeUser(w, u)}
Run or narrate your approach, then ask the coach.