Nicer errors for autoenv commands
This commit is contained in:
parent
59cd51b132
commit
632c6d1cd9
|
@ -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();
|
let mut hasher = DefaultHasher::new();
|
||||||
content.hash(&mut hasher);
|
content.hash(&mut hasher);
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,13 @@ impl WholeStreamCommand for AutoenvUnTrust {
|
||||||
let mut allowed: Trusted = toml::from_str(doc.as_str()).unwrap_or_else(|_| Trusted::new());
|
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();
|
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())
|
fs::write(config_path, toml::to_string(&allowed).unwrap())
|
||||||
.expect("Couldn't write to toml file");
|
.expect("Couldn't write to toml file");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user