Add verbose error for LED node missing

This commit is contained in:
Luke D Jones
2020-09-24 08:15:40 +12:00
parent 5753160e91
commit 8d59f89438
2 changed files with 11 additions and 4 deletions

View File

@@ -152,7 +152,12 @@ impl crate::CtrlTask for CtrlKbdBacklight {
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.read(true) .read(true)
.open(&self.bright_node) .open(&self.bright_node)
.map_err(|err| RogError::Path((&self.bright_node).into(), err))?; .map_err(|err| {
match err.kind() {
std::io::ErrorKind::NotFound => RogError::MissingLedBrightNode((&self.bright_node).into(), err),
_ => RogError::Path((&self.bright_node).into(), err),
}
})?;
let mut buf = [0u8; 1]; let mut buf = [0u8; 1];
file.read_exact(&mut buf) file.read_exact(&mut buf)
.map_err(|err| RogError::Read("buffer".into(), err))?; .map_err(|err| RogError::Read("buffer".into(), err))?;

View File

@@ -1,7 +1,7 @@
use std::fmt;
use std::convert::From;
use intel_pstate::PStateError; use intel_pstate::PStateError;
use rog_fan_curve::CurveError; use rog_fan_curve::CurveError;
use std::convert::From;
use std::fmt;
#[derive(Debug)] #[derive(Debug)]
pub enum RogError { pub enum RogError {
@@ -19,6 +19,7 @@ pub enum RogError {
FanCurve(CurveError), FanCurve(CurveError),
DoTask(String), DoTask(String),
MissingFunction(String), MissingFunction(String),
MissingLedBrightNode(String, std::io::Error),
} }
impl fmt::Display for RogError { impl fmt::Display for RogError {
@@ -39,6 +40,7 @@ impl fmt::Display for RogError {
RogError::FanCurve(err) => write!(f, "Custom fan-curve error: {}", err), RogError::FanCurve(err) => write!(f, "Custom fan-curve error: {}", err),
RogError::DoTask(deets) => write!(f, "Task error: {}", deets), RogError::DoTask(deets) => write!(f, "Task error: {}", deets),
RogError::MissingFunction(deets) => write!(f, "Missing functionality: {}", deets), RogError::MissingFunction(deets) => write!(f, "Missing functionality: {}", deets),
RogError::MissingLedBrightNode(path, error) => write!(f, "Led node at {} is missing, please check you have the required patch or dkms module installed: {}", path, error),
} }
} }
} }
@@ -55,4 +57,4 @@ impl From<CurveError> for RogError {
fn from(err: CurveError) -> Self { fn from(err: CurveError) -> Self {
RogError::FanCurve(err) RogError::FanCurve(err)
} }
} }