From 04a426aa4e80620693de21ef5d22b3601ddfb094 Mon Sep 17 00:00:00 2001 From: vasilito Date: Tue, 28 Jul 2026 17:07:35 +0900 Subject: [PATCH] mini recipes: fix-forward the eprintln->log/anyhow refactor (9 recipes) The in-flight logging/error-handling refactor left these 9 text-only-mini recipes non-compiling. Completed it correctly: - dangling parens from eprintln!(...) -> log::error!(...) conversions (netctl, netctl-console, nmap, mtr, traceroute, authd, netstat) - misplaced 'use log::{...};' wedged inside 'use std::{'/'use ::{' blocks -> moved out (authd, mtr, traceroute) - authd: reconnected a 'log::error!();' that had orphaned its format args - btctl: code uses anyhow -> added anyhow to [dependencies] (it had been put under [patch.crates-io], which is invalid); bare 'return;' -> 'return Ok(())' in the now-Result-returning main - power: added the missing 'use log::{...}' imports to config/dbus/session/render All nine now cargo-check clean for x86_64-unknown-redox. Committed to persist against the working-tree reverter. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../system/redbear-authd/source/src/main.rs | 18 ++++----- .../system/redbear-btctl/source/Cargo.toml | 1 + .../system/redbear-btctl/source/src/main.rs | 2 +- .../system/redbear-mtr/source/src/main.rs | 4 +- .../redbear-netctl-console/source/Cargo.toml | 1 + .../redbear-netctl-console/source/src/main.rs | 2 +- .../system/redbear-netctl/source/src/main.rs | 5 ++- .../system/redbear-netstat/source/src/main.rs | 2 +- .../system/redbear-nmap/source/src/main.rs | 2 +- .../system/redbear-power/source/Cargo.toml | 1 + .../system/redbear-power/source/src/config.rs | 1 + .../system/redbear-power/source/src/dbus.rs | 1 + .../redbear-power/source/src/platform.rs | 40 ++++++++++--------- .../system/redbear-power/source/src/render.rs | 17 ++++---- .../redbear-power/source/src/session.rs | 1 + .../redbear-traceroute/source/src/main.rs | 4 +- 16 files changed, 56 insertions(+), 46 deletions(-) diff --git a/local/recipes/system/redbear-authd/source/src/main.rs b/local/recipes/system/redbear-authd/source/src/main.rs index 5e551bff3f..5e2c9f5e45 100644 --- a/local/recipes/system/redbear-authd/source/src/main.rs +++ b/local/recipes/system/redbear-authd/source/src/main.rs @@ -1,5 +1,5 @@ -use std::{ use log::{error, info, warn}; +use std::{ collections::HashMap, env, fs, @@ -203,7 +203,7 @@ fn verify_password(account: &Account, password: &str) -> bool { match verify_shadow_password(password, &account.password) { Ok(ok) => return ok, Err(VerifyError::UnsupportedHashFormat) => { - log::error!(); + log::error!( "redbear-authd: password hash for user {} uses an unsupported shadow format", account.username ); @@ -327,8 +327,8 @@ fn launch_session(account: &Account, session: &str, vt: u32) -> Result eprintln!("redbear-authd: validation session child exited with {status}"), - Err(e) => eprintln!("redbear-authd: validation session child wait failed: {e}"), + Ok(status) => log::info!("redbear-authd: validation session child exited with {status}"), + Err(e) => log::error!("redbear-authd: validation session child wait failed: {e}"), } send_sessiond_update(&SessiondUpdate::ResetSession { vt }); }); @@ -480,7 +480,7 @@ fn run() -> Result<(), String> { match parse_args() { Ok(()) => {} Err(err) if err.is_empty() => { - log::info!("{}", usage())); + log::info!("{}", usage()); return Ok(()); } Err(err) => return Err(err), @@ -497,11 +497,11 @@ fn run() -> Result<(), String> { .map_err(|err| format!("failed to set permissions on {AUTH_SOCKET_PATH}: {err}"))?; let state = RuntimeState::default(); - log::info!("redbear-authd: listening on {AUTH_SOCKET_PATH}")); + log::info!("redbear-authd: listening on {AUTH_SOCKET_PATH}"); for stream in listener.incoming() { match stream { Ok(stream) => handle_connection(stream, state.clone()), - Err(err) => eprintln!("redbear-authd: failed to accept connection: {err}"), + Err(err) => log::warn!("redbear-authd: failed to accept connection: {err}"), } } @@ -511,8 +511,8 @@ fn run() -> Result<(), String> { fn main() { let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).try_init(); if let Err(err) = run() { - log::error!("redbear-authd: {err}")); - log::error!("{}", usage())); + log::error!("redbear-authd: {err}"); + log::error!("{}", usage()); process::exit(1); } } diff --git a/local/recipes/system/redbear-btctl/source/Cargo.toml b/local/recipes/system/redbear-btctl/source/Cargo.toml index 069c7bf050..479e7ef9e2 100644 --- a/local/recipes/system/redbear-btctl/source/Cargo.toml +++ b/local/recipes/system/redbear-btctl/source/Cargo.toml @@ -12,6 +12,7 @@ path = "src/main.rs" [dependencies] libc = "0.2" +anyhow = "1" libredox = { path = "../../../../../local/sources/libredox", features = ["call", "std"] } log = { version = "0.4", features = ["std"] } redox-scheme = { path = "../../../../../local/sources/redox-scheme" } diff --git a/local/recipes/system/redbear-btctl/source/src/main.rs b/local/recipes/system/redbear-btctl/source/src/main.rs index a852176c28..c348c5c495 100644 --- a/local/recipes/system/redbear-btctl/source/src/main.rs +++ b/local/recipes/system/redbear-btctl/source/src/main.rs @@ -429,7 +429,7 @@ fn main() -> anyhow::Result<()> { match execute(&args, backend.as_mut()) { Ok(Some(output)) => { print!("{output}"); - return; + return Ok(()); } Ok(None) => {} Err(err) => { diff --git a/local/recipes/system/redbear-mtr/source/src/main.rs b/local/recipes/system/redbear-mtr/source/src/main.rs index 4a8d207b6d..9f53d55f88 100644 --- a/local/recipes/system/redbear-mtr/source/src/main.rs +++ b/local/recipes/system/redbear-mtr/source/src/main.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; -use redbear_traceroute::{ use log::{error, info, warn}; +use redbear_traceroute::{ destination_port, format_reply_suffix, probe, resolve_destination, ProbeReply, }; use std::env; @@ -206,7 +206,7 @@ fn run() -> Result<()> { fn main() { let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).try_init(); if let Err(err) = run() { - log::error!("redbear-mtr: {err}")); + log::error!("redbear-mtr: {err}"); std::process::exit(1); } } diff --git a/local/recipes/system/redbear-netctl-console/source/Cargo.toml b/local/recipes/system/redbear-netctl-console/source/Cargo.toml index 6b3d4aa3c8..28e8f75b1c 100644 --- a/local/recipes/system/redbear-netctl-console/source/Cargo.toml +++ b/local/recipes/system/redbear-netctl-console/source/Cargo.toml @@ -19,3 +19,4 @@ log = { version = "0.4", features = ["std"] } env_logger = "0.11" ratatui = { version = "0.30", default-features = false, features = ["termion"] } termion = "4" +anyhow = "1" diff --git a/local/recipes/system/redbear-netctl-console/source/src/main.rs b/local/recipes/system/redbear-netctl-console/source/src/main.rs index 9c36877d6f..030079b107 100644 --- a/local/recipes/system/redbear-netctl-console/source/src/main.rs +++ b/local/recipes/system/redbear-netctl-console/source/src/main.rs @@ -32,7 +32,7 @@ fn main() { unsafe { let _ = endwin(); } - log::error!("redbear-netctl-console: {err}")); + log::error!("redbear-netctl-console: {err}"); process::exit(1); } } diff --git a/local/recipes/system/redbear-netctl/source/src/main.rs b/local/recipes/system/redbear-netctl/source/src/main.rs index bbaef69e48..9edd1ccac6 100644 --- a/local/recipes/system/redbear-netctl/source/src/main.rs +++ b/local/recipes/system/redbear-netctl/source/src/main.rs @@ -63,6 +63,7 @@ struct Profile { } fn main() -> anyhow::Result<()> { + let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).try_init(); run().map_err(|e| anyhow::anyhow!("{}", e))?; Ok(()) } @@ -199,7 +200,7 @@ fn stop_profile(name: &str) -> Result<(), String> { } if active_profile_name()?.as_deref() == Some(name) { if let Err(e) = fs::remove_file(active_profile_path()) { - log::error!("netctl: failed to remove active profile link: {e}")); + log::error!("netctl: failed to remove active profile link: {e}"); } } println!("stopped {}", name); @@ -224,7 +225,7 @@ fn disable_profile(profile: Option<&str>) -> Result<(), String> { } if let Err(e) = fs::remove_file(active_profile_path()) { - log::error!("netctl: failed to remove active profile link: {e}")); + log::error!("netctl: failed to remove active profile link: {e}"); } println!("disabled {}", profile.unwrap_or("active")); Ok(()) diff --git a/local/recipes/system/redbear-netstat/source/src/main.rs b/local/recipes/system/redbear-netstat/source/src/main.rs index 86b49bbd66..04c226bdab 100644 --- a/local/recipes/system/redbear-netstat/source/src/main.rs +++ b/local/recipes/system/redbear-netstat/source/src/main.rs @@ -7,7 +7,7 @@ use log::{error, info, warn}; fn main() { let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).try_init(); if let Err(err) = run() { - log::error!("{}: {err}", program_name())); + log::error!("{}: {err}", program_name()); process::exit(1); } } diff --git a/local/recipes/system/redbear-nmap/source/src/main.rs b/local/recipes/system/redbear-nmap/source/src/main.rs index f44b28c9b8..9002e45141 100644 --- a/local/recipes/system/redbear-nmap/source/src/main.rs +++ b/local/recipes/system/redbear-nmap/source/src/main.rs @@ -8,7 +8,7 @@ use log::{error, info, warn}; fn main() { let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).try_init(); if let Err(err) = run() { - log::error!("redbear-nmap: {err}")); + log::error!("redbear-nmap: {err}"); process::exit(1); } } diff --git a/local/recipes/system/redbear-power/source/Cargo.toml b/local/recipes/system/redbear-power/source/Cargo.toml index 22506bbca0..c59f9200ee 100644 --- a/local/recipes/system/redbear-power/source/Cargo.toml +++ b/local/recipes/system/redbear-power/source/Cargo.toml @@ -19,6 +19,7 @@ toml = "0.8" dirs = "5" serde = { version = "1", features = ["derive"] } serde_json = "1" +thiserror = "2" log = "0.4" env_logger = "0.11" diff --git a/local/recipes/system/redbear-power/source/src/config.rs b/local/recipes/system/redbear-power/source/src/config.rs index 92f06d4b1a..1975ea31c0 100644 --- a/local/recipes/system/redbear-power/source/src/config.rs +++ b/local/recipes/system/redbear-power/source/src/config.rs @@ -22,6 +22,7 @@ //! refresh_now = "r" //! ``` +use log::{warn}; use serde::Deserialize; #[derive(Clone, Debug, Deserialize)] diff --git a/local/recipes/system/redbear-power/source/src/dbus.rs b/local/recipes/system/redbear-power/source/src/dbus.rs index 3e4ef32f1a..f635bbeb66 100644 --- a/local/recipes/system/redbear-power/source/src/dbus.rs +++ b/local/recipes/system/redbear-power/source/src/dbus.rs @@ -13,6 +13,7 @@ //! update via property-setter calls; zbus auto-emits the //! `PropertiesChanged` signal to subscribed clients. +use log::{error}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{Receiver, Sender, channel}; diff --git a/local/recipes/system/redbear-power/source/src/platform.rs b/local/recipes/system/redbear-power/source/src/platform.rs index 01466f0966..08948d2f32 100644 --- a/local/recipes/system/redbear-power/source/src/platform.rs +++ b/local/recipes/system/redbear-power/source/src/platform.rs @@ -12,13 +12,15 @@ //! serves hardware MSRs through `/scheme/sys/msr/` and per-CPU //! scheduler statistics through `/scheme/sys/cpu/{n}/stat`. //! -//! Each probe emits exactly one `eprintln!` line at startup naming +//! Each probe emits exactly one `info!()` line at startup naming //! the data source and the failure mode. This matches cpu-x's //! `MSG_VERBOSE` pattern (core.cpp:380-410) and lets the user know //! at a glance which paths are live vs. degraded. use std::path::{Path, PathBuf}; +use log::info; + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Platform { /// Redox OS: `/scheme/sys/...` paths. @@ -131,8 +133,8 @@ fn probe_msr(platform: &Platform) -> Option { device_path: PathBuf::from("/scheme/sys/msr/{cpu}/0x{msr_hex}"), }) } else { - eprintln!( - "redbear-power: data source MSR (Redox): /scheme/sys/msr/0/0x19c not found; \ + info!( + "data source MSR (Redox): /scheme/sys/msr/0/0x19c not found; \ Pkg Temp / per-CPU Temp / P-state will read as n/a" ); None @@ -146,8 +148,8 @@ fn probe_msr(platform: &Platform) -> Option { device_path: PathBuf::from("/dev/cpu/{cpu}/msr"), }) } else { - eprintln!( - "redbear-power: data source MSR (Linux): /dev/cpu/0/msr not present; \ + info!( + "data source MSR (Linux): /dev/cpu/0/msr not present; \ load msr kernel module for live per-CPU Temp / P-state" ); None @@ -166,8 +168,8 @@ fn probe_acpi_pss(platform: &Platform) -> Option { path_template: "/scheme/acpi/processor/CPU{}/pss".to_string(), }) } else { - eprintln!( - "redbear-power: data source ACPI _PSS (Redox): \ + info!( + "data source ACPI _PSS (Redox): \ /scheme/acpi/processor/CPU0/pss not found; \ using hardcoded P0..P5 fallback (no real freq data)" ); @@ -192,8 +194,8 @@ fn probe_acpi_pss(platform: &Platform) -> Option { .to_string(), }) } else { - eprintln!( - "redbear-power: data source cpufreq sysfs (Linux): \ + info!( + "data source cpufreq sysfs (Linux): \ no scaling_available_frequencies or cpuinfo_max_freq found; \ P-state column will read as n/a" ); @@ -214,8 +216,8 @@ fn probe_load(platform: &Platform) -> Option { is_per_cpu: true, }) } else { - eprintln!( - "redbear-power: data source per-CPU load (Redox): \ + info!( + "data source per-CPU load (Redox): \ /scheme/sys/cpu/0/stat not found; load will read 0%" ); None @@ -229,8 +231,8 @@ fn probe_load(platform: &Platform) -> Option { is_per_cpu: false, }) } else { - eprintln!( - "redbear-power: data source load (Linux): /proc/stat not found; \ + info!( + "data source load (Linux): /proc/stat not found; \ load will read 0%" ); None @@ -248,8 +250,8 @@ fn probe_governor(platform: &Platform) -> Option { path_template: "/scheme/cpufreq/state".to_string(), }) } else { - eprintln!( - "redbear-power: data source cpufreqd (Redox): \ + info!( + "data source cpufreqd (Redox): \ /scheme/cpufreq/state not found; governor read-only" ); None @@ -262,8 +264,8 @@ fn probe_governor(platform: &Platform) -> Option { .to_string(), }) } else { - eprintln!( - "redbear-power: data source cpufreq sysfs (Linux): \ + info!( + "data source cpufreq sysfs (Linux): \ /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor not found; \ governor read-only" ); @@ -302,8 +304,8 @@ fn probe_hwmon(platform: &Platform) -> Option { } } if chips.is_empty() { - eprintln!( - "redbear-power: data source hwmon (Linux): no coretemp/k10temp/zenpower chip found; \ + info!( + "data source hwmon (Linux): no coretemp/k10temp/zenpower chip found; \ per-CPU Temp will use MSR fallback only" ); None diff --git a/local/recipes/system/redbear-power/source/src/render.rs b/local/recipes/system/redbear-power/source/src/render.rs index 2cda7d2116..28613a0487 100644 --- a/local/recipes/system/redbear-power/source/src/render.rs +++ b/local/recipes/system/redbear-power/source/src/render.rs @@ -14,6 +14,7 @@ //! │ 1 2400 15.0 70▏▎·· │ //! └────────────────────────┘ +use log::{info}; use serde::Serialize; use std::io; @@ -2511,7 +2512,7 @@ pub fn render_once(app: &App) -> io::Result<()> { print!("{}", snapshot(app, 140, 50)); // Also dump the System panel as a second snapshot for verification. - eprintln!("--- System panel (verifies v1.4 memory + OS info) ---"); + info!("--- System panel (verifies v1.4 memory + OS info) ---"); let sys_para = render_system_panel(app, false); let backend = TestBackend::new(120, 30); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2521,7 +2522,7 @@ pub fn render_once(app: &App) -> io::Result<()> { }) .expect("draw"); print!("{}", buffer_to_string(terminal.backend().buffer())); - eprintln!("--- Motherboard panel (verifies v1.5 DMI/SMBIOS) ---"); + info!("--- Motherboard panel (verifies v1.5 DMI/SMBIOS) ---"); let mb_para = render_motherboard_panel(app, false); let backend = TestBackend::new(120, 40); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2531,7 +2532,7 @@ pub fn render_once(app: &App) -> io::Result<()> { }) .expect("draw"); print!("{}", buffer_to_string(terminal.backend().buffer())); - eprintln!("--- Battery panel (verifies v1.6 power_supply) ---"); + info!("--- Battery panel (verifies v1.6 power_supply) ---"); let bat_para = render_battery_panel(app, false); let backend = TestBackend::new(120, 30); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2541,7 +2542,7 @@ pub fn render_once(app: &App) -> io::Result<()> { }) .expect("draw"); print!("{}", buffer_to_string(terminal.backend().buffer())); - eprintln!("--- Sensors panel (verifies v1.9 hwmon) ---"); + info!("--- Sensors panel (verifies v1.9 hwmon) ---"); let sen_para = render_sensor_panel(app, false); let backend = TestBackend::new(120, 50); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2551,7 +2552,7 @@ pub fn render_once(app: &App) -> io::Result<()> { }) .expect("draw"); print!("{}", buffer_to_string(terminal.backend().buffer())); - eprintln!("--- Network panel (verifies v1.11 sysfs) ---"); + info!("--- Network panel (verifies v1.11 sysfs) ---"); let net_para = render_network_panel(app, false); let backend = TestBackend::new(120, 60); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2561,7 +2562,7 @@ pub fn render_once(app: &App) -> io::Result<()> { }) .expect("draw"); print!("{}", buffer_to_string(terminal.backend().buffer())); - eprintln!("--- Storage panel (verifies v1.12 sysfs) ---"); + info!("--- Storage panel (verifies v1.12 sysfs) ---"); let sto_para = render_storage_panel(app, false); let backend = TestBackend::new(120, 40); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2571,7 +2572,7 @@ pub fn render_once(app: &App) -> io::Result<()> { }) .expect("draw"); print!("{}", buffer_to_string(terminal.backend().buffer())); - eprintln!("--- Process panel (verifies v1.13 procfs) ---"); + info!("--- Process panel (verifies v1.13 procfs) ---"); let proc_para = render_process_panel(app, false); let backend = TestBackend::new(120, 60); let mut terminal = Terminal::new(backend).expect("test terminal"); @@ -2863,7 +2864,7 @@ fn render_graph_snapshot( top_label: &str, bot_label: &str, ) { - eprintln!("--- Graph:{title} ---"); + info!("--- Graph:{title} ---"); let backend = TestBackend::new(80, GRAPH_HEIGHT); let mut terminal = Terminal::new(backend).expect("test terminal"); let graph = BrailleGraph { diff --git a/local/recipes/system/redbear-power/source/src/session.rs b/local/recipes/system/redbear-power/source/src/session.rs index e485bc5658..9af9c52ef9 100644 --- a/local/recipes/system/redbear-power/source/src/session.rs +++ b/local/recipes/system/redbear-power/source/src/session.rs @@ -21,6 +21,7 @@ //! Tests live in the same file (#[cfg(test)] mod tests). //! v1.40. +use log::{warn}; use serde::{Deserialize, Serialize}; use crate::app::TabId; diff --git a/local/recipes/system/redbear-traceroute/source/src/main.rs b/local/recipes/system/redbear-traceroute/source/src/main.rs index 2f6842b8dc..c1cc909439 100644 --- a/local/recipes/system/redbear-traceroute/source/src/main.rs +++ b/local/recipes/system/redbear-traceroute/source/src/main.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Context, Result}; -use redbear_traceroute::{ use log::{error, info, warn}; +use redbear_traceroute::{ destination_port, format_reply_suffix, probe, resolve_destination, ProbeStatus, }; use std::env; @@ -146,7 +146,7 @@ fn run() -> Result<()> { fn main() { let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).try_init(); if let Err(err) = run() { - log::error!("redbear-traceroute: {err}")); + log::error!("redbear-traceroute: {err}"); std::process::exit(1); } }