Use ShellError instead of Error

This commit is contained in:
Sam Hedin 2020-06-24 00:36:50 +02:00
parent 4e0b863cd1
commit 1bb24e0561

View File

@ -39,7 +39,9 @@ impl DirectorySpecificEnvironment {
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
content.hash(&mut hasher); content.hash(&mut hasher);
if trusted.files.get(wdirenv.to_str().unwrap()) == Some(&hasher.finish().to_string()) { if trusted.files.get(wdirenv.to_str().unwrap_or(""))
== Some(&hasher.finish().to_string())
{
return Ok(content.parse::<toml::Value>().or_else(|_| { return Ok(content.parse::<toml::Value>().or_else(|_| {
Err(ShellError::untagged_runtime_error( Err(ShellError::untagged_runtime_error(
"Could not parse .nu-env file. Is it well-formed?", "Could not parse .nu-env file. Is it well-formed?",
@ -65,21 +67,21 @@ impl DirectorySpecificEnvironment {
toml_doc toml_doc
.get("env") .get("env")
.ok_or_else(|| { .ok_or_else(|| {
Error::new( ShellError::untagged_runtime_error(format!(
ErrorKind::InvalidData, "[env] section missing in {:?}",
format!("[env] section missing in {:?}", wdirenv), wdirenv
) ))
})? })?
.as_table() .as_table()
.ok_or_else(|| { .ok_or_else(|| {
Error::new( ShellError::untagged_runtime_error(format!(
ErrorKind::InvalidData, "[env] section malformed in {:?}",
format!("[env] section malformed in {:?}", wdirenv), wdirenv
) ))
})? })?
.iter() .iter()
.for_each(|(dir_env_key, dir_env_val)| { .for_each(|(dir_env_key, dir_env_val)| {
let dir_env_val: EnvVal = dir_env_val.as_str().unwrap().into(); let dir_env_val: EnvVal = dir_env_val.as_str().unwrap_or_else("").into();
//This condition is to make sure variables in parent directories don't overwrite variables set by subdirectories. //This condition is to make sure variables in parent directories don't overwrite variables set by subdirectories.
if !vars_to_add.contains_key(dir_env_key) { if !vars_to_add.contains_key(dir_env_key) {