Code Room
Code reviewMedium
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.
Learn the concepts
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.