cloudflare/cloudflared · error · ErrInsuficientFields
expected file descriptor information to have %d fields got %
Error message
expected file descriptor information to have %d fields got %d: %w
What it means
ParseSysctlFileDescriptorInformation parses whitespace-separated sysctl output (e.g. `kern.openfiles` style limits) and expects exactly 3 whitespace-separated fields, with the current open-file count at index 0 and the max at index 2. This error is thrown when strconv.ParseUint fails on field 0, meaning the 'current files' value is not a plain base-10 unsigned integer. It wraps the strconv error so the offending text is included in the message.
Source
Thrown at diagnostic/system_collector_utils.go:234
maxFilesField = 2
fileDescriptorLimitsFields = 3
)
fields := strings.Fields(output)
if len(fields) != fileDescriptorLimitsFields {
return nil,
fmt.Errorf(
"expected file descriptor information to have %d fields got %d: %w",
fileDescriptorLimitsFields,
len(fields),
ErrInsuficientFields,
)
}
fileDescriptorCurrent, err := strconv.ParseUint(fields[openFilesField], 10, 64)
if err != nil {
return nil, fmt.Errorf(
"error parsing files current field '%s': %w",
fields[openFilesField],
err,
)
}
fileDescriptorMaximum, err := strconv.ParseUint(fields[maxFilesField], 10, 64)
if err != nil {
return nil, fmt.Errorf("error parsing files max field '%s': %w", fields[maxFilesField], err)
}
return &FileDescriptorInformation{fileDescriptorMaximum, fileDescriptorCurrent}, nil
}
func ParseFileDescriptorInformationFromKV(
output string,
fileDescriptorMaximumKey string,
fileDescriptorCurrentKey string,View on GitHub (pinned to 2253eeeb25)
Solutions
- Check the raw sysctl output and pass only the line containing the numeric fields, stripping any key/label prefixes
- Verify the queried sysctl key returns the 3-field numeric format expected (open-files current, intermediate, max)
- If output contains labels, use ParseFileDescriptorInformationFromKV instead, which matches keys explicitly
- Sanitize values (remove commas, units, whitespace) before parsing
Example fix
// before info, err := ParseSysctlFileDescriptorInformation(out) // out = "kern.openfiles: 12" // after line := "12 0 256" // extract numeric fields only info, err := ParseSysctlFileDescriptorInformation(line)
Defensive patterns
Strategy: validation
Validate before calling
fields := strings.Fields(out)
if len(fields) != 3 {
return fmt.Errorf("unexpected sysctl fd output %q", out)
}
if _, err := strconv.ParseUint(fields[0], 10, 64); err != nil {
return fmt.Errorf("non-numeric open-files field %q: %w", fields[0], err)
} Type guard
func isNumericFields(out string, n int) bool {
fields := strings.Fields(out)
if len(fields) != n { return false }
for _, f := range fields {
if _, err := strconv.ParseUint(f, 10, 64); err != nil { return false }
}
return true
} Try / catch
info, err := ParseSysctlFileDescriptorInformation(out)
if err != nil {
var parseErr *strconv.NumError
if errors.Is(err, ErrInsuficientFields) || errors.As(err, &parseErr) {
// log raw output and skip FD metrics rather than failing collection
return nil, nil
}
return nil, err
} Prevention
- Log the raw command output when parsing diagnostics so format regressions are visible
- Only feed the parser the specific output line it expects, not entire command stdout
- Sanitize thousands separators and units before numeric parsing
- Pin/verify sysctl output format across the OS versions you support
When it happens
Trigger: Calling ParseSysctlFileDescriptorInformation with output whose first whitespace-delimited token is not a decimal number: empty input, a labeled line like "current 10 max 100" (words shift the indices), localized output, or a value with units/commas such as "1,024".
Common situations: sysctl command output format differs across OS versions or locales; the caller captured stderr instead of stdout; a different sysctl key was queried so the output contains a header or label; macOS vs Linux field ordering differences.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- error parsing files max field '%s': %w
- error parsing files current field '%s': %w
- parsing file descriptor information: %w, key=%s
- error parsing OriginCert: %v
- parsing memory information: %w, key=%s
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/b5fa183851570c7b.
Report an issue: GitHub.