They admit it's contrived, but this isn't very convincing
func printSum(a, b string) error {
x, err := strconv.Atoi(a)
if err != nil {
return fmt.Errorf("invalid integer: %q", a)
}
y, err := strconv.Atoi(b)
if err != nil {
return fmt.Errorf("invalid integer: %q", b)
}
fmt.Println("result:", x + y)
return nil
}
It's not adding anything that the Atoi function couldn't have reported. That's a perfect case for blindly passing an error up the stack.
It does, it says which one of the two integers was incorrect