{"record":{"id":"b5fa183851570c7b","repo":"cloudflare/cloudflared","slug":"expected-file-descriptor-information-to-have-d-fi","errorCode":null,"errorMessage":"expected file descriptor information to have %d fields got %d: %w","messagePattern":"expected file descriptor information to have (.+?) fields got (.+?): %w","errorType":"exception","errorClass":"ErrInsuficientFields","httpStatus":null,"severity":"error","filePath":"diagnostic/system_collector_utils.go","lineNumber":234,"sourceCode":"\t\tmaxFilesField              = 2\n\t\tfileDescriptorLimitsFields = 3\n\t)\n\n\tfields := strings.Fields(output)\n\n\tif len(fields) != fileDescriptorLimitsFields {\n\t\treturn nil,\n\t\t\tfmt.Errorf(\n\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,","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/diagnostic/system_collector_utils.go#L216-L252","documentation":"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.","triggerScenarios":"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\".","commonSituations":"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.","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"],"exampleFix":"// before\ninfo, err := ParseSysctlFileDescriptorInformation(out) // out = \"kern.openfiles: 12\"\n// after\nline := \"12 0 256\" // extract numeric fields only\ninfo, err := ParseSysctlFileDescriptorInformation(line)","handlingStrategy":"validation","validationCode":"fields := strings.Fields(out)\nif len(fields) != 3 {\n    return fmt.Errorf(\"unexpected sysctl fd output %q\", out)\n}\nif _, err := strconv.ParseUint(fields[0], 10, 64); err != nil {\n    return fmt.Errorf(\"non-numeric open-files field %q: %w\", fields[0], err)\n}","typeGuard":"func isNumericFields(out string, n int) bool {\n    fields := strings.Fields(out)\n    if len(fields) != n { return false }\n    for _, f := range fields {\n        if _, err := strconv.ParseUint(f, 10, 64); err != nil { return false }\n    }\n    return true\n}","tryCatchPattern":"info, err := ParseSysctlFileDescriptorInformation(out)\nif err != nil {\n    var parseErr *strconv.NumError\n    if errors.Is(err, ErrInsuficientFields) || errors.As(err, &parseErr) {\n        // log raw output and skip FD metrics rather than failing collection\n        return nil, nil\n    }\n    return nil, err\n}","preventionTips":["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"],"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"}