{"record":{"id":"007a339fce7cd7f9","repo":"sinelaw/fresh","slug":"cpu-detection-not-implemented-for-this-platform","errorCode":null,"errorMessage":"CPU detection not implemented for this platform","messagePattern":"CPU 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":358,"sourceCode":"        }\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\",\n            ))\n        }\n    }\n}\n\n/// Apply memory limit via setrlimit (fallback method)\n#[cfg(target_os = \"linux\")]\nfn apply_memory_limit_setrlimit(bytes: u64) -> io::Result<()> {\n    use nix::sys::resource::{setrlimit, Resource};\n\n    // Set RLIMIT_AS (address space / virtual memory limit)\n    // On 32-bit platforms, rlim_t is u32, so we need to convert carefully.\n    // If bytes exceeds what rlim_t can represent, clamp to rlim_t::MAX.\n    let limit = bytes as nix::libc::rlim_t;\n    setrlimit(Resource::RLIMIT_AS, limit, limit)\n        .map_err(|e| io::Error::other(format!(\"setrlimit AS failed: {}\", e)))","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor-core/src/process_limits.rs#L340-L376","documentation":"cpu_count() reports the number of logical CPUs for process limit setup. Like total_memory_mb, only Linux is implemented; the cfg(not(target_os = \"linux\")) arm returns io::ErrorKind::Unsupported, explicitly stating detection is not yet ported to this platform.","triggerScenarios":"Calling process_limits::cpu_count() (public) on macOS, Windows, BSD, or any non-Linux target when initializing CPU-based process limits.","commonSituations":"Multi-platform builds initializing resource limits unconditionally; CI matrix running on macOS/Windows runners.","solutions":["Skip CPU limit configuration when cpu_count() returns Unsupported","Implement the platform arm via std::thread::available_parallelism() or the num_cpus crate","Gate limit-setting code with #[cfg(target_os = \"linux\")]","Default to a sensible fallback core count (e.g. 1) when detection fails"],"exampleFix":"// before\nlet cores = cpu_count()?;\n// after\nlet cores = cpu_count().unwrap_or_else(|_| std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1));","handlingStrategy":"fallback","validationCode":"#[cfg(not(target_os = \"linux\"))] let cores = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1); // pre-resolve before calling cpu_count()","typeGuard":null,"tryCatchPattern":"let cores = cpu_count().unwrap_or_else(|e| { debug_assert!(e.kind() == io::ErrorKind::Unsupported); 1 });","preventionTips":["Use std::thread::available_parallelism() as the portable default","Compile-time-gate CPU limit configuration to Linux","Keep a unit test that fails when a public API returns Unsupported on a supported tier"],"tags":["platform","unsupported","cpu","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-16T09:17:16.951Z"}