slimtoolkit/slim · error

error parsing GID field - %s (%v)

Error message

error parsing GID field - %s (%v)

What it means

Same parser as the UID case: ParsePasswdRecord converts passwd field 3 (GID) with strconv.Atoi and returns this error when it is not a valid integer. The record is returned partially populated so the caller can inspect which line failed.

Source

Thrown at pkg/sysidentity/sysidentity.go:335

	record.Username = parts[0]
	record.Password = parts[1]
	record.Info = parts[4]
	record.Home = parts[5]
	record.Shell = strings.TrimSpace(parts[6])

	if _, found := NoLoginShells[record.Shell]; found {
		record.NoLoginShell = true
	}

	var err error
	record.UID, err = strconv.Atoi(parts[2])
	if err != nil {
		return record, fmt.Errorf("error parsing UID field - %s (%v)", parts[2], err)
	}

	record.GID, err = strconv.Atoi(parts[3])
	if err != nil {
		return record, fmt.Errorf("error parsing GID field - %s (%v)", parts[3], err)
	}

	return record, nil
}

const (
	HasShadowFileRecord = "x"
)

func (ref PasswdRecord) UsesShadow() bool {
	if ref.Password == HasShadowFileRecord {
		return true
	}

	return false
}

var NoLoginShells = map[string]struct{}{

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Fix the offending /etc/passwd line so the GID field is numeric
  2. Find bad lines with: awk -F: '$4 !~ /^[0-9]+$/{print}' /etc/passwd
  3. Ensure the GID references a real group in /etc/group or create it
  4. Re-run the identity read; the error names the bad field value

Example fix

// before
svc:x:1500:users::/home/svc:/bin/sh
// after
svc:x:1500:1500::/home/svc:/bin/sh
Defensive patterns

Strategy: validation

Validate before calling

func validPasswdGID(line string) bool {
    parts := strings.Split(line, ":")
    if len(parts) < 4 { return false }
    _, err := strconv.Atoi(parts[3])
    return err == nil
}

Try / catch

rec, err := sysidentity.ParsePasswdRecord(line)
if err != nil && strings.Contains(err.Error(), "GID field") {
    log.Warnf("bad GID in passwd entry: %v", err)
    continue
}

Prevention

When it happens

Trigger: ReadPasswdData -> ParsePasswdRecord on a passwd line whose fourth (GID) field is empty, alphabetic, or otherwise non-numeric.

Common situations: Corrupted or hand-edited /etc/passwd; group name mistakenly placed in the GID column; truncated lines from a bad provisioning script.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/f8494da02c1829fc. Report an issue: GitHub.