{"record":{"id":"225ad7a080115c8e","repo":"sinelaw/fresh","slug":"memory-detection-not-implemented-for-this-platform","errorCode":null,"errorMessage":"Memory detection not implemented for this platform","messagePattern":"Memory detection not implemented for this platform","errorType":"exception","errorClass":"io::Error (Unsupported)","httpStatus":null,"severity":"warning","filePath":"crates/fresh-editor-core/src/process_limits.rs","lineNumber":318,"sourceCode":"fn get_uid() -> u32 {\n    unsafe { libc::getuid() }\n}\n\n/// System resource information utilities\npub struct SystemResources;\n\nimpl SystemResources {\n    /// Get total system memory in megabytes\n    pub fn total_memory_mb() -> io::Result<u64> {\n        #[cfg(target_os = \"linux\")]\n        {\n            Self::linux_total_memory_mb()\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                \"Memory detection not implemented for this platform\",\n            ))\n        }\n    }\n\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","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor-core/src/process_limits.rs#L300-L336","documentation":"total_memory_mb() reports the machine's total RAM so the editor can enforce process memory limits. Only Linux detection is implemented; on any other target OS the cfg(not(target_os = \"linux\")) arm returns io::ErrorKind::Unsupported. This is an explicit not-yet-ported error, not a runtime fault.","triggerScenarios":"Calling process_limits::total_memory_mb() (public) on macOS, Windows, BSD, or any non-Linux target. Also affects anything downstream that depends on memory limits being initialized on those platforms.","commonSituations":"Building/running the editor on macOS or Windows with process limits enabled; cross-platform test suites calling limit setup unconditionally.","solutions":["Skip or degrade process memory limiting when total_memory_mb() returns Unsupported","Implement the platform arm using sysinfo/libc (host_statistics on macOS, GlobalMemoryStatusEx on Windows, sysconf on BSD)","Use a cross-platform crate such as the `sysinfo` crate for detection","Only call limit-setting code under #[cfg(target_os = \"linux\")]"],"exampleFix":"// before\nlet mem = total_memory_mb()?;\nset_rlimit(RLIMIT_AS, mem)?;\n// after\nmatch total_memory_mb() {\n    Ok(mem) => set_rlimit(RLIMIT_AS, mem)?,\n    Err(e) if e.kind() == io::ErrorKind::Unsupported => log::info!(\"memory limits unavailable on this platform\"),\n    Err(e) => return Err(e),\n}","handlingStrategy":"fallback","validationCode":"#[cfg(not(target_os = \"linux\"))] let can_detect_memory = false;\n#[cfg(target_os = \"linux\")] let can_detect_memory = true;","typeGuard":null,"tryCatchPattern":"match total_memory_mb() { Ok(mb) => apply_limit(mb), Err(e) if e.kind() == io::ErrorKind::Unsupported => log::info!(\"limits unsupported here\"), Err(e) => return Err(e.into()), }","preventionTips":["Gate platform-specific limit setup behind cfg attributes","Prefer std::thread::available_parallelism()/sysinfo crate over hand-rolled per-OS code","Add cross-platform CI to catch unported code paths early"],"tags":["platform","unsupported","memory","rust"],"backgroundTag":"unsupported-platform","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"}