Nicer errors for autoenv commands

This commit is contained in:
Sam Hedin 2020-06-22 17:32:44 +02:00
parent 59cd51b132
commit 632c6d1cd9
2 changed files with 13 additions and 2 deletions

View File

@ -45,7 +45,12 @@ impl WholeStreamCommand for AutoenvTrust {
}
};
let content = std::fs::read_to_string(&file_to_trust)?;
let content = std::fs::read_to_string(&file_to_trust).or_else(|_| {
Err(ShellError::untagged_runtime_error(
"No .nu-env file in the given directory",
))
})?;
let mut hasher = DefaultHasher::new();
content.hash(&mut hasher);

View File

@ -70,7 +70,13 @@ impl WholeStreamCommand for AutoenvUnTrust {
let mut allowed: Trusted = toml::from_str(doc.as_str()).unwrap_or_else(|_| Trusted::new());
let file_to_untrust = file_to_untrust.to_string_lossy().to_string();
allowed.files.remove(&file_to_untrust);
if allowed.files.remove(&file_to_untrust).is_none() {
return
Err(ShellError::untagged_runtime_error(
"No .nu-env file to untrust in the given directory",
));
}
fs::write(config_path, toml::to_string(&allowed).unwrap())
.expect("Couldn't write to toml file");