cloudflare/cloudflared · error

error parsing files current field '%s': %w

Error message

error parsing files current field '%s': %w

What it means

ParseSysctlFileDescriptorInformation could not convert the 'current open files' field of sysctl-style output into a uint64, so strconv.ParseUint failed and the library wraps that error with the offending field value. The parser expects whitespace-separated numeric fields (current, then max files); a non-numeric token in the first field triggers this. It is thrown when the command output is not in the anticipated numeric format.

Source

Thrown at diagnostic/system_collector_utils.go:224

}

type FileDescriptorInformation struct {
	FileDescriptorMaximum uint64
	FileDescriptorCurrent uint64
}

func ParseSysctlFileDescriptorInformation(output string) (*FileDescriptorInformation, error) {
	const (
		openFilesField             = 0
		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 {

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Inspect the quoted field value in the error message to see the offending non-numeric token
  2. Sanitize the command output to strip labels/headers so only the numeric fields remain before parsing
  3. Check that the command that produced the output matches the expected sysctl format (3 numeric fields) and is not mixing in stderr
  4. Parse the underlying sysctl/ulimit command with explicit flags that output raw numbers

Example fix

// before
info, err := ParseSysctlFileDescriptorInformation(rawOutput)
// after
numericOutput := strings.Join(strings.Fields(stripLabels(rawOutput)), " ")
info, err := ParseSysctlFileDescriptorInformation(numericOutput)
if err != nil {
    log.Warn().Err(err).Msg("file descriptor output not numeric")
}
Defensive patterns

Strategy: validation

Validate before calling

fields := strings.Fields(output)
if len(fields) != 3 {
    return errors.New("unexpected fd output shape")
}
if _, err := strconv.ParseUint(fields[0], 10, 64); err != nil {
    return fmt.Errorf("current fd field not numeric: %q", fields[0])
}

Try / catch

info, err := ParseSysctlFileDescriptorInformation(output)
if err != nil {
    var numErr *strconv.NumError
    if errors.As(err, &numErr) {
        log.Warn().Str("field", numErr.Num).Msg("non-numeric fd output; skipping")
        return nil, err
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling ParseSysctlFileDescriptorInformation (via collectFileDescriptorInformation) with output whose third-token count check passed but whose first field is not a decimal number — e.g. a header line like 'File descriptors:' or a label such as 'open' slipped into the parsed token stream.

Common situations: Non-English or labeled sysctl output (e.g. macOS/FreeBSD 'kern.maxfiles' variants) that includes text tokens; capturing stderr plus stdout so labels mix with numbers; a changed command or flags producing extra prose; locale-dependent formatting.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/45d2092cee279497. Report an issue: GitHub.