mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Clean up unwrap()'s. Print out info in asusctl if error
This commit is contained in:
@@ -27,3 +27,9 @@ impl fmt::Display for ProfileError {
|
||||
}
|
||||
|
||||
impl std::error::Error for ProfileError {}
|
||||
|
||||
impl From<std::io::Error> for ProfileError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
ProfileError::Io(err)
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ impl Profile {
|
||||
.unwrap_or_else(|_| panic!("{} not found", &PLATFORM_PROFILE));
|
||||
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
file.read_to_string(&mut buf)?;
|
||||
Ok(buf.as_str().into())
|
||||
}
|
||||
|
||||
@@ -52,17 +52,18 @@ impl Profile {
|
||||
.unwrap_or_else(|_| panic!("{} not found", &PLATFORM_PROFILES));
|
||||
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
file.read_to_string(&mut buf)?;
|
||||
Ok(buf.rsplit(' ').map(|p| p.into()).collect())
|
||||
}
|
||||
|
||||
pub fn set_profile(profile: Profile) {
|
||||
pub fn set_profile(profile: Profile) -> Result<(), ProfileError> {
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.open(PLATFORM_PROFILE)
|
||||
.unwrap_or_else(|_| panic!("{} not found", PLATFORM_PROFILE));
|
||||
|
||||
file.write_all(<&str>::from(profile).as_bytes()).unwrap();
|
||||
file.write_all(<&str>::from(profile).as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user