{"record":{"id":"45d2092cee279497","repo":"cloudflare/cloudflared","slug":"error-parsing-files-current-field-s-w","errorCode":null,"errorMessage":"error parsing files current field '%s': %w","messagePattern":"error parsing files current field '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diagnostic/system_collector_utils.go","lineNumber":224,"sourceCode":"}\n\ntype FileDescriptorInformation struct {\n\tFileDescriptorMaximum uint64\n\tFileDescriptorCurrent uint64\n}\n\nfunc ParseSysctlFileDescriptorInformation(output string) (*FileDescriptorInformation, error) {\n\tconst (\n\t\topenFilesField             = 0\n\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 {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/diagnostic/system_collector_utils.go#L206-L242","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the quoted field value in the error message to see the offending non-numeric token","Sanitize the command output to strip labels/headers so only the numeric fields remain before parsing","Check that the command that produced the output matches the expected sysctl format (3 numeric fields) and is not mixing in stderr","Parse the underlying sysctl/ulimit command with explicit flags that output raw numbers"],"exampleFix":"// before\ninfo, err := ParseSysctlFileDescriptorInformation(rawOutput)\n// after\nnumericOutput := strings.Join(strings.Fields(stripLabels(rawOutput)), \" \")\ninfo, err := ParseSysctlFileDescriptorInformation(numericOutput)\nif err != nil {\n    log.Warn().Err(err).Msg(\"file descriptor output not numeric\")\n}","handlingStrategy":"validation","validationCode":"fields := strings.Fields(output)\nif len(fields) != 3 {\n    return errors.New(\"unexpected fd output shape\")\n}\nif _, err := strconv.ParseUint(fields[0], 10, 64); err != nil {\n    return fmt.Errorf(\"current fd field not numeric: %q\", fields[0])\n}","typeGuard":null,"tryCatchPattern":"info, err := ParseSysctlFileDescriptorInformation(output)\nif err != nil {\n    var numErr *strconv.NumError\n    if errors.As(err, &numErr) {\n        log.Warn().Str(\"field\", numErr.Num).Msg(\"non-numeric fd output; skipping\")\n        return nil, err\n    }\n    return nil, err\n}","preventionTips":["Strip labels/headers from the command output so only numeric fields are passed to the parser","Do not merge stderr into the parsed stdout stream","Pin the exact command/flags that emit the expected 3-numeric-field format","Validate field count and numeric-ness before calling the parser"],"tags":["go","parsing","unix","file-descriptors"],"backgroundTag":"unexpected-response-shape","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"}