{"record":{"id":"1e44e89e41e67c37","repo":"cloudflare/cloudflared","slug":"parsing-file-descriptor-information-w-key-s","errorCode":null,"errorMessage":"parsing file descriptor information: %w, key=%s","messagePattern":"parsing file descriptor information: %w, key=(.+?)","errorType":"exception","errorClass":"ErrKeyNotFound","httpStatus":null,"severity":"error","filePath":"diagnostic/system_collector_utils.go","lineNumber":262,"sourceCode":"\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 {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"parsing file descriptor information: %w, key=%s\",\n\t\t\tErrKeyNotFound,\n\t\t\tfileDescriptorMaximumKey,\n\t\t)\n\t}\n\n\tfileDescriptorCurrent, exists := pairs[fileDescriptorCurrentKey]\n\tif !exists {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"parsing file descriptor information: %w, key=%s\",\n\t\t\tErrKeyNotFound,\n\t\t\tfileDescriptorCurrentKey,\n\t\t)\n\t}\n\n\treturn &FileDescriptorInformation{fileDescriptorMaximum, fileDescriptorCurrent}, nil\n}\n","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/diagnostic/system_collector_utils.go#L244-L280","documentation":"ParseFileDescriptorInformationFromKV scans colon-separated key/value output for the given file-descriptor maximum key. This error is returned when the requested key is absent from the parsed pairs, wrapped with ErrKeyNotFound. It indicates the output text does not contain a recognizable `<key>: <number>` entry for the maximum file-descriptor limit.","triggerScenarios":"Calling ParseFileDescriptorInformationFromKV with an output string missing the max key: wrong key string (case/spacing mismatch), the command output changed format across OS versions, empty output, or output where values failed ParseUint and were dropped from the pairs map.","commonSituations":"macOS `ulimit -Hn`/launchctl output vs Linux `ulimit -n` wording differences; container runtimes omitting limits; querying the wrong sysctl key; trailing whitespace or tabs after the key name.","solutions":["Print the raw output and confirm the exact key spelling, including case and spacing, matches what is passed as fileDescriptorMaximumKey","Use the key constant/string the OS actually emits (e.g. \"maxfiles\" vs \"open files\")","Handle empty output from the upstream command before parsing (check command exit status)","If values may be non-numeric, provide a lenient mapper or sanitize the values first"],"exampleFix":"// before\ninfo, err := ParseFileDescriptorInformationFromKV(out, \"MaxFiles\", \"OpenFiles\")\n// after\ninfo, err := ParseFileDescriptorInformationFromKV(out, \"maxfiles\", \"openfiles\") // exact key emitted by the OS","handlingStrategy":"try-catch","validationCode":"if !strings.Contains(out, maxKey+\":\") {\n    return fmt.Errorf(\"output %q missing key %q\", out, maxKey)\n}","typeGuard":null,"tryCatchPattern":"info, err := ParseFileDescriptorInformationFromKV(out, maxKey, curKey)\nif err != nil {\n    if errors.Is(err, ErrKeyNotFound) {\n        // degrade: skip FD diagnostic or try alternate key set\n        return nil, nil\n    }\n    return nil, err\n}","preventionTips":["Capture and store raw command output to diagnose key-mismatch issues","Use the exact key strings emitted by the OS, ideally as shared constants","Check command exit status and non-empty output before parsing","Test parsing against real output samples from every supported platform"],"tags":["go","parsing","file-descriptors","key-not-found","kv-parsing"],"backgroundTag":"missing-config-key","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}