diff --git a/src/daemon.rs b/src/daemon.rs index 854b5d6..5da1ca7 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -640,8 +640,19 @@ pub fn daemon_init(settings: Settings, config: Config) -> Arc> { } // Make a cpu struct for each cpu listed - for cpu in list_cpus() { - daemon.cpus.push(cpu); + match list_cpus() { + Ok(cpus) => { + + for cpu in cpus { + daemon.cpus.push(cpu); + } + + }, + Err(e) => { + + daemon.logger.log(&format!("Failed to read from CPUs: {:?}", e), logger::Severity::Error) + + }, } let daemon_mutex = Arc::new(Mutex::new(daemon)); diff --git a/src/interface.rs b/src/interface.rs index 496a0fe..2b0cc11 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -141,8 +141,15 @@ pub trait Getter { impl Getter for Get { fn freq(&self, raw: bool) { - let f = check_cpu_freq(&list_cpus()); - print_freq(f, raw); + match list_cpus() { + Ok(cpus) => { + let f = check_cpu_freq(&cpus); + print_freq(f, raw); + }, + Err(e) => { + eprint!("Failed to get cpu information, an error occured: {:?}", e); + }, + } } fn power(&self, raw: bool) { @@ -230,26 +237,54 @@ impl Getter for Get { } fn cpus(&self, raw: bool) { - let cpus = list_cpus(); - match check_cpu_name() { - Ok(name) => print_cpus(cpus, name, raw), - Err(_) => println!("Failed get list of cpus"), - }; + let cpus_result = list_cpus(); + match cpus_result { + Ok(cpus) => { + match check_cpu_name() { + Ok(name) => print_cpus(cpus, name, raw), + Err(_) => println!("Failed get list of cpus"), + }; + }, + Err(e) => { + eprintln!("Failed to get cpu information, an error occured: {:?}", e); + }, + } } fn speeds(&self, raw: bool) { - let speeds = list_cpu_speeds(); - print_cpu_speeds(speeds, raw); + let speeds_result = list_cpu_speeds(); + match speeds_result { + Ok(speeds) => { + print_cpu_speeds(speeds, raw); + }, + Err(e) => { + eprintln!("Failed to get cpu speed information, an error occured: {:?}", e); + }, + } } fn temp(&self, raw: bool) { - let cpu_temp = list_cpu_temp(); - print_cpu_temp(cpu_temp, raw); + let cpu_temp_result = list_cpu_temp(); + match cpu_temp_result { + Ok(cpu_temp) => { + print_cpu_temp(cpu_temp, raw); + }, + Err(e) => { + eprintln!("Failed to get cpu temperature information, an error occured: {:?}", e); + }, + } } fn govs(&self, raw: bool) { - let govs = list_cpu_governors(); - print_cpu_governors(govs, raw); + let govs_result = list_cpu_governors(); + match govs_result { + Ok(govs) => { + print_cpu_governors(govs, raw); + }, + Err(e) => { + eprintln!("Failed to get cpu governor information, an error occured: {:?}", e); + }, + } } fn bat_cond(&self, raw: bool) { diff --git a/src/system.rs b/src/system.rs index 915bab0..3932d18 100644 --- a/src/system.rs +++ b/src/system.rs @@ -281,7 +281,7 @@ mod tests { #[test] fn check_cpu_freq_acs_test() { - assert!(check_cpu_freq(&list_cpus()) > 0.0); + assert!(check_cpu_freq(&list_cpus().unwrap()) > 0.0); } #[test]