sinelaw/fresh · warning · io::Error (Unsupported)

CPU detection not implemented for this platform

Error message

CPU detection not implemented for this platform

What it means

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.

Solutions

  1. Skip CPU limit configuration when cpu_count() returns Unsupported
  2. Implement the platform arm via std::thread::available_parallelism() or the num_cpus crate
  3. Gate limit-setting code with #[cfg(target_os = "linux")]
  4. Default to a sensible fallback core count (e.g. 1) when detection fails

Example fix

// before
let cores = cpu_count()?;
// after
let cores = cpu_count().unwrap_or_else(|_| std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1));
Defensive patterns

Strategy: fallback

Validate before calling

#[cfg(not(target_os = "linux"))] let cores = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1); // pre-resolve before calling cpu_count()

Try / catch

let cores = cpu_count().unwrap_or_else(|e| { debug_assert!(e.kind() == io::ErrorKind::Unsupported); 1 });

Prevention

When it happens

Trigger: Calling process_limits::cpu_count() (public) on macOS, Windows, BSD, or any non-Linux target when initializing CPU-based process limits.

Common situations: Multi-platform builds initializing resource limits unconditionally; CI matrix running on macOS/Windows runners.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/007a339fce7cd7f9. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor-core/src/process_limits.rs:358

        }

        Err(io::Error::new(
            io::ErrorKind::InvalidData,
            "Could not parse MemTotal from /proc/meminfo",
        ))
    }

    /// Get total number of CPU cores
    pub fn cpu_count() -> io::Result<usize> {
        #[cfg(target_os = "linux")]
        {
            Ok(num_cpus())
        }

        #[cfg(not(target_os = "linux"))]
        {
            // TODO: Implement for other platforms
            Err(io::Error::new(
                io::ErrorKind::Unsupported,
                "CPU detection not implemented for this platform",
            ))
        }
    }
}

/// Apply memory limit via setrlimit (fallback method)
#[cfg(target_os = "linux")]
fn apply_memory_limit_setrlimit(bytes: u64) -> io::Result<()> {
    use nix::sys::resource::{setrlimit, Resource};

    // Set RLIMIT_AS (address space / virtual memory limit)
    // On 32-bit platforms, rlim_t is u32, so we need to convert carefully.
    // If bytes exceeds what rlim_t can represent, clamp to rlim_t::MAX.
    let limit = bytes as nix::libc::rlim_t;
    setrlimit(Resource::RLIMIT_AS, limit, limit)
        .map_err(|e| io::Error::other(format!("setrlimit AS failed: {}", e)))

View on GitHub (pinned to 67894ca546)