hashicorp/nomad · error

Unable to convert Uid to an int: %w

Error message

Unable to convert Uid to an int: %w

What it means

getUid converts the textual Uid field of a resolved user (os/user.User) to an int with strconv.Atoi. This error means the Uid string was not a valid integer, which normally indicates a corrupted or unusual user database entry rather than a Nomad problem. It is surfaced while dropDirPermissions resolves 'nobody'.

Source

Thrown at client/allocdir/fs_unix.go:72

	}

	gid, err := getGid(u)
	if err != nil {
		return err
	}

	if err := os.Chown(path, uid, gid); err != nil {
		return fmt.Errorf("Couldn't change owner/group of %v to (uid: %v, gid: %v): %w", path, uid, gid, err)
	}

	return nil
}

// getUid for a user
func getUid(u *user.User) (int, error) {
	uid, err := strconv.Atoi(u.Uid)
	if err != nil {
		return 0, fmt.Errorf("Unable to convert Uid to an int: %w", err)
	}

	return uid, nil
}

// getGid for a user
func getGid(u *user.User) (int, error) {
	gid, err := strconv.Atoi(u.Gid)
	if err != nil {
		return 0, fmt.Errorf("Unable to convert Gid to an int: %w", err)
	}

	return gid, nil
}

// linkOrCopy attempts to hardlink dst to src and fallsback to copying if the
// hardlink fails.
func linkOrCopy(src, dst string, uid, gid int, perm os.FileMode) error {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Run `getent passwd nobody` and fix the uid field in /etc/passwd (or the NSS source) if it is not numeric.
  2. Restore a standard passwd file on minimal/broken images.
  3. Validate all users referenced by Nomad task configs have numeric uid/gid fields.
  4. Restart the client after repairing the user database.

Example fix

// before: malformed passwd entry
nobody:x:unknown:65534::/nonexistent:/sbin/nologin
// after: numeric uid
nobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin
Defensive patterns

Strategy: validation

Validate before calling

// preflight: referenced users must have numeric ids
for _, name := range []string{"nobody", taskUser} {
    u, err := user.Lookup(name)
    if err != nil { return err }
    if _, err := strconv.Atoi(u.Uid); err != nil {
        return fmt.Errorf("user %s has non-numeric uid %q", name, u.Uid)
    }
}

Try / catch

if err := td.Build(); err != nil {
    if strings.Contains(err.Error(), "convert Uid to an int") {
        log.Printf("corrupt passwd entry on client host; repair /etc/passwd")
    }
    return err
}

Prevention

When it happens

Trigger: strconv.Atoi(u.Uid) returned an error after users.Lookup("nobody") (or another user lookup) returned a User whose Uid string is non-numeric.

Common situations: Manually edited /etc/passwd with a malformed uid field; NSS backends returning unexpected strings; corrupted passwd databases on the client host.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/daae40c6c61bdad1. Report an issue: GitHub.