hashicorp/nomad · error

error parsing gid: %w

Error message

error parsing gid: %w

What it means

Fires in LookupUnix when the group ID returned by the OS user database cannot be parsed as an integer — the system's passwd/group source (e.g. LDAP or NSS) returned a non-numeric GID for the user.

Source

Thrown at helper/users/lookup.go:44

// LookupUnix returns the UID, GID, and home directory for username or returns
// an error. ID values are int to work well with Go library functions.
//
// Will always fail on Windows and Plan 9.
func LookupUnix(username string) (int, int, string, error) {
	u, err := Lookup(username)
	if err != nil {
		return 0, 0, "", fmt.Errorf("error looking up user %q: %w", username, err)
	}

	uid, err := strconv.Atoi(u.Uid)
	if err != nil {
		return 0, 0, "", fmt.Errorf("error parsing uid: %w", err)
	}

	gid, err := strconv.Atoi(u.Gid)
	if err != nil {
		return 0, 0, "", fmt.Errorf("error parsing gid: %w", err)
	}

	return uid, gid, u.HomeDir, nil
}

// lock is used to serialize all user lookup at the process level, because
// some NSS implementations are not concurrency safe
var lock sync.Mutex

// internalLookupUser username while holding a global process lock.
func internalLookupUser(username string) (*user.User, error) {
	lock.Lock()
	defer lock.Unlock()
	return user.Lookup(username)
}

// Current returns the current user, acquired while holding a global process
// lock.

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Fix the gid column for the user in /etc/passwd (must be a number)
  2. Correct gidNumber in the LDAP/NSS directory source if centralized
  3. Recreate the user with standard tooling to regenerate valid entries

Example fix

// before
svc:x:1000:admin   # non-numeric gid
// after
svc:x:1000:1000    # numeric gid
Defensive patterns

Strategy: validation

Validate before calling

u, err := user.Lookup(username)
if err != nil {
	return err
}
if _, err := strconv.Atoi(u.Gid); err != nil {
	return fmt.Errorf("user %q has non-numeric gid %q in passwd/NSS source", username, u.Gid)
}
uid, gid, home, err := users.LookupUnix(username)

Type guard

func hasValidGid(u *user.User) bool {
	_, err := strconv.Atoi(u.Gid)
	return err == nil
}

Try / catch

uid, gid, home, err := users.LookupUnix(username)
if err != nil {
	if strings.Contains(err.Error(), "error parsing gid") {
		return fmt.Errorf("corrupt passwd entry for %q — fix gid column: %w", username, err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling users.LookupUnix for a user whose group id field is non-numeric — bad /etc/passwd gid column, or an NSS/LDAP source returning invalid gidNumber.

Common situations: Manual /etc/passwd edits with a typo in the gid column; LDAP/SSSD entries with malformed gidNumber; provisioning scripts writing corrupt entries.

Related errors


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