Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V8040. The value of the variable is...
menu mobile close menu
Additional information
toggle menu Contents

V8040. The value of the variable is overwritten before it is used.

Aug 06 2026

The analyzer has detected a variable whose value was overwritten before it was used.

The example:

func createUser(req *http.Request) error {
  user, err := parseUser(req)
  if err != nil {
    return err
  }

  err = validateUser(user)
  err = saveUser(user)

  return err
}

The return value of the validateUser function is assigned to the err variable. On the next line, a new value is assigned to the same variable. This means that the result of validateUser was not handled.

To fix this, add a check for the err variable immediately after assigning it the return value of validateUser:

func createUser(req *http.Request) error {
  user, err := parseUser(req)
  if err != nil {
    return err
  }

  err = validateUser(user)

  if err != nil {
    return err
  }

  err = saveUser(user)

  return err
}