cloudflare/cloudflared · error · ErrKeyNotFound
parsing memory information: %w, key=%s
Error message
parsing memory information: %w, key=%s
What it means
ParseMemoryInformationFromKV parses colon-separated key/value output to find memory maximum and available values using the provided mapper. This error is returned when the memoryMaximumKey is not present in the parsed pairs, wrapped with ErrKeyNotFound, so MemoryInformation cannot be computed.
Source
Thrown at diagnostic/system_collector_utils.go:296
return &FileDescriptorInformation{fileDescriptorMaximum, fileDescriptorCurrent}, nil
}
type MemoryInformation struct {
MemoryMaximum uint64 // size in KB
MemoryCurrent uint64 // size in KB
}
func ParseMemoryInformationFromKV(
output string,
memoryMaximumKey string,
memoryAvailableKey string,
mapper func(field string) (uint64, error),
) (*MemoryInformation, error) {
pairs := findColonSeparatedPairs(output, []string{memoryMaximumKey, memoryAvailableKey}, mapper)
memoryMaximum, exists := pairs[memoryMaximumKey]
if !exists {
return nil, fmt.Errorf("parsing memory information: %w, key=%s", ErrKeyNotFound, memoryMaximumKey)
}
memoryAvailable, exists := pairs[memoryAvailableKey]
if !exists {
return nil, fmt.Errorf("parsing memory information: %w, key=%s", ErrKeyNotFound, memoryAvailableKey)
}
memoryCurrent := memoryMaximum - memoryAvailable
return &MemoryInformation{memoryMaximum, memoryCurrent}, nil
}
func RawSystemInformation(osInfoRaw string, memoryInfoRaw string, fdInfoRaw string, disksRaw string) string {
var builder strings.Builder
formatInfo := func(info string, builder *strings.Builder) {
if info == "" {
builder.WriteString("No information\n")View on GitHub (pinned to 2253eeeb25)
Solutions
- Compare the passed memoryMaximumKey against the literal key text in the raw output
- Provide a mapper that strips units and handles special values (e.g. treat "max"/"unlimited" as a sentinel) before ParseUint
- Ensure the source file/command actually contains a memory-max key (cgroups may omit memory.max when unlimited)
- Check the upstream command output is non-empty and successful before parsing
Example fix
// before
mapper := func(f string) (uint64, error) { return strconv.ParseUint(f, 10, 64) }
info, err := ParseMemoryInformationFromKV(out, "MemMax", "MemAvailable", mapper)
// after
info, err := ParseMemoryInformationFromKV(out, "MemTotal", "MemAvailable", mapper) // key as emitted by source Defensive patterns
Strategy: try-catch
Validate before calling
if !strings.Contains(out, memoryMaximumKey+":") {
return fmt.Errorf("output %q missing key %q", out, memoryMaximumKey)
} Try / catch
mem, err := ParseMemoryInformationFromKV(out, maxKey, availKey, mapper)
if err != nil {
if errors.Is(err, ErrKeyNotFound) {
// degrade: report memory info as unavailable
return nil, nil
}
return nil, err
} Prevention
- Match key names against the literal source (procfs/cgroup/sysctl) before parsing
- Supply a mapper that handles unit suffixes and sentinel values like "max"
- Confirm the memory-max key exists in the environment (cgroup v2 may omit it when unlimited)
- Guard against empty output and command failures upstream of the parser
When it happens
Trigger: Calling ParseMemoryInformationFromKV with output lacking the maximum-memory key: wrong key string (e.g. "MemTotal" vs "total memory"), units in values that the mapper rejects (dropping the pair), empty output, or OS output format changes.
Common situations: cgroup v1 vs v2 memory limit files with different labels; free(1)/sysctl output wording differences across platforms; values like "16 GB" or "unlimited" failing a numeric mapper; reading the wrong memory file (e.g. memory.max absent, meaning no limit).
Related errors
- parsing file descriptor information: %w, key=%s
- error parsing OriginCert: %v
- error parsing files current field '%s': %w
- expected file descriptor information to have %d fields got %
- error parsing files max field '%s': %w
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/7d35a6434f7bde63.
Report an issue: GitHub.