{"record":{"id":"fc0948212339849b","repo":"elkowar/eww","slug":"eww-doesn-t-support-your-os-for-getting-the-batter","errorCode":null,"errorMessage":"Eww doesn't support your OS for getting the battery capacity","messagePattern":"Eww doesn't support your OS for getting the battery capacity","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eww/src/config/system_stats.rs","lineNumber":254,"sourceCode":"        json.push_str(&format!(\n            r#\"\"BAT{}\": {{ \"status\": \"{}\", \"capacity\": {} }}, \"#,\n            bat.get(1).unwrap().as_str(),\n            bat.get(2).unwrap().as_str(),\n            bat.get(3).unwrap().as_str(),\n        ))\n    }\n\n    json.push_str(&format!(r#\"\"total_avg\": {}}}\"#, re_total.captures(&batteries).unwrap().get(1).unwrap().as_str()));\n    Ok(json)\n}\n\n#[cfg(not(target_os = \"macos\"))]\n#[cfg(not(target_os = \"linux\"))]\n#[cfg(not(target_os = \"netbsd\"))]\n#[cfg(not(target_os = \"freebsd\"))]\n#[cfg(not(target_os = \"openbsd\"))]\npub fn get_battery_capacity() -> Result<String> {\n    Err(anyhow::anyhow!(\"Eww doesn't support your OS for getting the battery capacity\"))\n}\n\npub fn net() -> String {\n    let (ref mut last_refresh, ref mut networks) = &mut *NETWORKS.lock().unwrap();\n\n    networks.refresh_list();\n    let elapsed = last_refresh.next_refresh();\n\n    networks\n        .iter()\n        .map(|(name, data)| {\n            let transmitted = data.transmitted() as f64 / elapsed.as_secs_f64();\n            let received = data.received() as f64 / elapsed.as_secs_f64();\n            (name, serde_json::json!({ \"NET_UP\": transmitted, \"NET_DOWN\": received }))\n        })\n        .collect::<serde_json::Value>()\n        .to_string()\n}","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/elkowar/eww/blob/48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa/crates/eww/src/config/system_stats.rs#L236-L272","documentation":"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.","triggerScenarios":"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.","commonSituations":"Building/running eww on an unsupported platform such as Windows; cross-compiling for an unusual target and using battery widgets.","solutions":["Run eww on a supported OS (Linux, macOS, or the listed BSDs)","Avoid battery widgets/variables on unsupported platforms","Contribute a get_battery_capacity implementation for your OS behind a new cfg gate"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// cfg-gate battery usage in dependent code\n#[cfg(any(target_os = \"linux\", target_os = \"macos\"))]\nlet capacity = system_stats::get_battery_capacity();","typeGuard":null,"tryCatchPattern":"match get_battery_capacity() {\n    Ok(v) => v,\n    Err(_) => String::from(\"N/A\"), // fallback display\n}","preventionTips":["Only use battery widgets on supported platforms","Provide a fallback display value in widgets","Check eww's platform support matrix before porting"],"tags":["eww","platform","battery","unsupported-os"],"backgroundTag":"unsupported-platform","analyzedSha":"48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa","analyzedAt":"2026-09-08T03:13:26.897Z","contentChangedAt":"2026-09-08T03:13:26.897Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}