Replace match with or_else

This commit is contained in:
Sam Hedin 2020-06-25 17:31:46 +02:00
parent b9c170d359
commit ce23b3b96e
2 changed files with 6 additions and 9 deletions

View File

@ -22,19 +22,16 @@ impl Trusted {
pub fn read_trusted() -> Result<Self, ShellError> { pub fn read_trusted() -> Result<Self, ShellError> {
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?; let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
let mut file = match std::fs::OpenOptions::new() let mut file = std::fs::OpenOptions::new()
.read(true) .read(true)
.create(true) .create(true)
.write(true) .write(true)
.open(config_path) .open(config_path)
{ .or_else(|_| {
Ok(p) => p, Err(ShellError::untagged_runtime_error(
Err(_) => {
return Err(ShellError::untagged_runtime_error(
"Couldn't open nu-env.toml", "Couldn't open nu-env.toml",
)); ))
} })?;
};
let mut doc = String::new(); let mut doc = String::new();
file.read_to_string(&mut doc)?; file.read_to_string(&mut doc)?;

View File

@ -49,7 +49,7 @@ impl DirectorySpecificEnvironment {
})?); })?);
} }
return Err(ShellError::untagged_runtime_error( return Err(ShellError::untagged_runtime_error(
format!("{:?} is untrusted. Run 'autoenv trust {:?}' and restart nushell to trust it.\nThis needs to be done after each change to the file.\n", wdirenv, wdirenv.parent().unwrap_or_else(|| &Path::new(""))))); format!("{:?} is untrusted. Run 'autoenv trust {:?}' and restart nushell to trust it.\nThis needs to be done after each change to the file.", wdirenv, wdirenv.parent().unwrap_or_else(|| &Path::new("")))));
} }
Err(ShellError::untagged_runtime_error("No trusted directories")) Err(ShellError::untagged_runtime_error("No trusted directories"))
} }