elkowar/eww · error

Eww doesn't support your OS for getting the battery capacity

Error message

Eww doesn't support your OS for getting the battery capacity

What it means

get_battery_capacity has platform-specific implementations for macOS, Linux, NetBSD, FreeBSD and OpenBSD, gated by cfg attributes. On any other OS, this stub is compiled and unconditionally returns this error, since eww has no battery-reading code path for that platform.

Solutions

  1. Run eww on a supported OS (Linux, macOS, or the listed BSDs)
  2. Avoid battery widgets/variables on unsupported platforms
  3. Contribute a get_battery_capacity implementation for your OS behind a new cfg gate
Defensive patterns

Strategy: fallback

Validate before calling

// cfg-gate battery usage in dependent code
#[cfg(any(target_os = "linux", target_os = "macos"))]
let capacity = system_stats::get_battery_capacity();

Try / catch

match get_battery_capacity() {
    Ok(v) => v,
    Err(_) => String::from("N/A"), // fallback display
}

Prevention

When it happens

Trigger: Any widget/config referencing battery capacity (e.g. the EWW_BATTERY variable or a battery stats call) on a target OS that is none of macos/linux/netbsd/freebsd/openbsd — e.g. Windows or a niche BSD.

Common situations: Building/running eww on an unsupported platform such as Windows; cross-compiling for an unusual target and using battery widgets.

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 elkowar/eww@48f5aa8b37 (2026-09-08). Data as JSON: /api/errors/fc0948212339849b. Report an issue: GitHub.

Appendix: source

Thrown at crates/eww/src/config/system_stats.rs:254

        json.push_str(&format!(
            r#""BAT{}": {{ "status": "{}", "capacity": {} }}, "#,
            bat.get(1).unwrap().as_str(),
            bat.get(2).unwrap().as_str(),
            bat.get(3).unwrap().as_str(),
        ))
    }

    json.push_str(&format!(r#""total_avg": {}}}"#, re_total.captures(&batteries).unwrap().get(1).unwrap().as_str()));
    Ok(json)
}

#[cfg(not(target_os = "macos"))]
#[cfg(not(target_os = "linux"))]
#[cfg(not(target_os = "netbsd"))]
#[cfg(not(target_os = "freebsd"))]
#[cfg(not(target_os = "openbsd"))]
pub fn get_battery_capacity() -> Result<String> {
    Err(anyhow::anyhow!("Eww doesn't support your OS for getting the battery capacity"))
}

pub fn net() -> String {
    let (ref mut last_refresh, ref mut networks) = &mut *NETWORKS.lock().unwrap();

    networks.refresh_list();
    let elapsed = last_refresh.next_refresh();

    networks
        .iter()
        .map(|(name, data)| {
            let transmitted = data.transmitted() as f64 / elapsed.as_secs_f64();
            let received = data.received() as f64 / elapsed.as_secs_f64();
            (name, serde_json::json!({ "NET_UP": transmitted, "NET_DOWN": received }))
        })
        .collect::<serde_json::Value>()
        .to_string()
}

View on GitHub (pinned to 48f5aa8b37)