{"record":{"id":"5ad8870e4cd27b47","repo":"sinelaw/fresh","slug":"could-not-parse-memtotal-from-proc-meminfo","errorCode":null,"errorMessage":"Could not parse MemTotal from /proc/meminfo","messagePattern":"Could not parse MemTotal from /proc/meminfo","errorType":"exception","errorClass":"io::Error (InvalidData)","httpStatus":null,"severity":"warning","filePath":"crates/fresh-editor-core/src/process_limits.rs","lineNumber":342,"sourceCode":"\n    #[cfg(target_os = \"linux\")]\n    fn linux_total_memory_mb() -> io::Result<u64> {\n        // Read from /proc/meminfo\n        let meminfo = std::fs::read_to_string(\"/proc/meminfo\")?;\n\n        for line in meminfo.lines() {\n            if line.starts_with(\"MemTotal:\") {\n                // Format: \"MemTotal:       16384000 kB\"\n                let parts: Vec<&str> = line.split_whitespace().collect();\n                if parts.len() >= 2 {\n                    if let Ok(kb) = parts[1].parse::<u64>() {\n                        return Ok(kb / 1024); // Convert KB to MB\n                    }\n                }\n            }\n        }\n\n        Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"Could not parse MemTotal from /proc/meminfo\",\n        ))\n    }\n\n    /// Get total number of CPU cores\n    pub fn cpu_count() -> io::Result<usize> {\n        #[cfg(target_os = \"linux\")]\n        {\n            Ok(num_cpus())\n        }\n\n        #[cfg(not(target_os = \"linux\"))]\n        {\n            // TODO: Implement for other platforms\n            Err(io::Error::new(\n                io::ErrorKind::Unsupported,\n                \"CPU detection not implemented for this platform\",","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor-core/src/process_limits.rs#L324-L360","documentation":"linux_total_memory_mb() parses /proc/meminfo looking for the MemTotal line, expecting a value in kB. If the file exists but no MemTotal entry can be found/parsed (or the file is empty/malformed), it returns io::ErrorKind::InvalidData with this message, since memory size cannot be established for limit enforcement.","triggerScenarios":"Calling total_memory_mb() on Linux when /proc/meminfo lacks a parseable 'MemTotal: <n> kB' line — e.g. exotic kernels, restricted containers with masked /proc/meminfo, or locale/number formatting anomalies in the file.","commonSituations":"Running inside a container where /proc is remounted or partially masked; non-standard embedded Linux without full procfs; security hardening that hides meminfo fields.","solutions":["Verify /proc/meminfo contains a MemTotal line (cat /proc/meminfo | grep MemTotal)","Unmask /proc/meminfo in the container (remove volume/bind mounts hiding it)","Fall back to getrusage/sysinfo(2) syscall or the sysinfo crate if procfs is unavailable","Treat the error as non-fatal and skip memory limiting"],"exampleFix":"// before\nlet mem = total_memory_mb()?;\n// after\nlet mem = total_memory_mb().unwrap_or_else(|e| {\n    log::warn!(\"memory detect failed: {e}; skipping limits\");\n    u64::MAX\n});","handlingStrategy":"fallback","validationCode":"let meminfo = std::fs::read_to_string(\"/proc/meminfo\")?;\nlet ok = meminfo.lines().any(|l| l.starts_with(\"MemTotal:\"));\nif !ok { /* skip limits or use fallback */ }","typeGuard":null,"tryCatchPattern":"match total_memory_mb() { Ok(mb) => apply_limit(mb), Err(e) if e.kind() == io::ErrorKind::InvalidData => log::warn!(\"procfs unreadable: {e}\"), Err(e) => return Err(e.into()), }","preventionTips":["In containers, ensure /proc/meminfo is not masked","Provide a syscall-based fallback (sysinfo(2)) for hardened environments","Treat limit detection as best-effort, never a hard startup dependency"],"tags":["linux","procfs","memory","parse-error"],"backgroundTag":"file-read-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}