{"record":{"id":"df716c71649a5c32","repo":"cloudflare/cloudflared","slug":"error-parsing-files-max-field-s-w","errorCode":null,"errorMessage":"error parsing files max field '%s': %w","messagePattern":"error parsing files max field '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diagnostic/system_collector_utils.go","lineNumber":243,"sourceCode":"\t\t\t\t\"expected file descriptor information to have %d fields got %d: %w\",\n\t\t\t\tfileDescriptorLimitsFields,\n\t\t\t\tlen(fields),\n\t\t\t\tErrInsuficientFields,\n\t\t\t)\n\t}\n\n\tfileDescriptorCurrent, err := strconv.ParseUint(fields[openFilesField], 10, 64)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"error parsing files current field '%s': %w\",\n\t\t\tfields[openFilesField],\n\t\t\terr,\n\t\t)\n\t}\n\n\tfileDescriptorMaximum, err := strconv.ParseUint(fields[maxFilesField], 10, 64)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing files max field '%s': %w\", fields[maxFilesField], err)\n\t}\n\n\treturn &FileDescriptorInformation{fileDescriptorMaximum, fileDescriptorCurrent}, nil\n}\n\nfunc ParseFileDescriptorInformationFromKV(\n\toutput string,\n\tfileDescriptorMaximumKey string,\n\tfileDescriptorCurrentKey string,\n) (*FileDescriptorInformation, error) {\n\tmapper := func(field string) (uint64, error) {\n\t\treturn strconv.ParseUint(field, 10, 64)\n\t}\n\n\tpairs := findColonSeparatedPairs(output, []string{fileDescriptorMaximumKey, fileDescriptorCurrentKey}, mapper)\n\n\tfileDescriptorMaximum, exists := pairs[fileDescriptorMaximumKey]\n\tif !exists {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/diagnostic/system_collector_utils.go#L225-L261","documentation":"ParseSysctlFileDescriptorInformation parses whitespace-separated sysctl file-descriptor limits and expects the maximum at whitespace field index 2. This error is returned when strconv.ParseUint fails on that field, i.e. the third token is not a base-10 unsigned integer. The wrapped strconv error and the offending string are included in the message.","triggerScenarios":"Calling ParseSysctlFileDescriptorInformation where fields[2] is non-numeric or empty: truncated output, output with fewer tokens that happened to still be 3 but labeled (e.g. \"10 open max\"), values with units like \"256K\", or a comma-separated number \"1,024\".","commonSituations":"OS-version differences in sysctl output; locale-formatted numbers with thousands separators; capturing the wrong command output; cgroup/container environments reporting abbreviated limits.","solutions":["Inspect the raw output and ensure the third whitespace-separated token is a plain decimal integer","Strip units, commas, or labels from the value before calling the parser","Prefer ParseFileDescriptorInformationFromKV when output is key/value formatted rather than positional","Confirm the sysctl command/version produces the expected 3-field numeric layout"],"exampleFix":"// before\nraw := \"10 0 1,024\" // thousands separator\ninfo, err := ParseSysctlFileDescriptorInformation(raw)\n// after\nraw = strings.ReplaceAll(raw, \",\", \"\")\ninfo, err := ParseSysctlFileDescriptorInformation(raw)","handlingStrategy":"validation","validationCode":"fields := strings.Fields(out)\nif len(fields) < 3 {\n    return fmt.Errorf(\"sysctl fd output too short: %q\", out)\n}\nif _, err := strconv.ParseUint(fields[2], 10, 64); err != nil {\n    return fmt.Errorf(\"non-numeric max-files field %q\", fields[2])\n}","typeGuard":"func hasValidUintField(out string, idx int) bool {\n    fields := strings.Fields(out)\n    if idx >= len(fields) { return false }\n    _, err := strconv.ParseUint(fields[idx], 10, 64)\n    return err == nil\n}","tryCatchPattern":"info, err := ParseSysctlFileDescriptorInformation(out)\nif err != nil {\n    var numErr *strconv.NumError\n    if errors.As(err, &numErr) {\n        // fall back to key/value parser or degrade gracefully\n        return nil, nil\n    }\n    return nil, err\n}","preventionTips":["Strip units (K/M) and thousands separators from numeric sysctl values before parsing","Verify field positions (max is index 2) against actual output on each target OS","Add table-driven tests with real sysctl samples per platform","Prefer the KV parser for label-bearing output"],"tags":["go","parsing","file-descriptors","sysctl","strconv"],"backgroundTag":"invalid-argument-format","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}