ClementTsang/bottom · error · anyhow::Error

Unsupported OS

Error message

Unsupported OS

What it means

get_io_usage on unsupported platforms (anything other than the specifically implemented OSes, e.g. not Linux, macOS, or FreeBSD in the target cfg) is a stub that immediately returns an error. It signals that disk I/O statistics harvesting is simply not implemented for the current operating system.

Solutions

  1. Verify the host OS is one with disk I/O support (Linux, macOS, FreeBSD)
  2. Gate I/O usage collection behind an OS check before calling
  3. Contribute/implement an IoHarvest collector for the target OS
  4. Handle the returned error gracefully and skip I/O metrics

Example fix

// before
let io = get_io_usage(&collector)?;
// after
match get_io_usage(&collector) {
    Ok(h) => Some(h),
    Err(e) if e.to_string().contains("Unsupported OS") => { log::warn!("io stats unsupported here"); None },
    Err(e) => return Err(e),
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Skip I/O collection on unsupported targets
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "freebsd")))]
let io_harvest: Option<IoHarvest> = None;

Try / catch

match get_io_usage(&collector) {
    Ok(h) => Some(h),
    Err(e) if e.to_string() == "Unsupported OS" => { log::info!("io stats not supported on this OS"); None },
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling get_io_usage (disk I/O harvest) while compiling/running on an OS that falls into the catch-all cfg branch, e.g. Windows or any target that is not freebsd/covered by other branches.

Common situations: Running the app on an unusual platform (e.g. NetBSD, Illumos) or after a Rust target/cfg change that no longer matches the implemented platform branches.

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 ClementTsang/bottom@b77d317502 (2026-09-07). Data as JSON: /api/errors/1c4005129fd0c1d9. Report an issue: GitHub.

Appendix: source

Thrown at src/collection/disks.rs:94

            for io in io_stats()?.into_iter() {
                let mount_point = io.device_name().to_string_lossy();

                io_hash.insert(
                    mount_point.to_string(),
                    Some(IoData {
                        read_bytes: io.read_bytes(),
                        write_bytes: io.write_bytes(),
                    }),
                );
            }

            Ok(io_hash)
        }
    }
    not(target_os = "freebsd") => {
        use crate::collection::DataCollector;
        pub fn get_io_usage(_collector: &DataCollector) -> anyhow::Result<IoHarvest> {
            anyhow::bail!("Unsupported OS");
        }
    }
    _ => {}
}

/// Whether to keep the current disk entry given the filters, disk name, and
/// disk mount. Precedence ordering in the case where name and mount filters
/// disagree, "allow" takes precedence over "deny".
///
/// For implementation, we do this as follows:
///
/// 1. Is the entry allowed through any filter? That is, does it match an entry
///    in a filter where `is_list_ignored` is `false`? If so, we always keep
///    this entry.
/// 2. Is the entry denied through any filter? That is, does it match an entry
///    in a filter where `is_list_ignored` is `true`? If so, we always deny this
///    entry.
/// 3. Anything else is allowed.

View on GitHub (pinned to b77d317502)