diff --git a/crates/nu-cli/src/env/directory_specific_environment.rs b/crates/nu-cli/src/env/directory_specific_environment.rs index 5fa5512660..3f1be5a0e7 100644 --- a/crates/nu-cli/src/env/directory_specific_environment.rs +++ b/crates/nu-cli/src/env/directory_specific_environment.rs @@ -2,14 +2,13 @@ use crate::commands::{self, autoenv::Trusted}; use commands::autoenv; use indexmap::{IndexMap, IndexSet}; use nu_errors::ShellError; -use nu_source::Span; use std::{ collections::hash_map::DefaultHasher, ffi::OsString, fmt::Debug, hash::{Hash, Hasher}, io::{Error, ErrorKind}, - path::PathBuf, + path::{Path, PathBuf}, }; type EnvKey = String; @@ -34,10 +33,7 @@ impl DirectorySpecificEnvironment { } } - fn toml_if_directory_is_trusted( - &self, - wdirenv: PathBuf, - ) -> Result { + fn toml_if_directory_is_trusted(&self, wdirenv: &PathBuf) -> Result { if let Some(trusted) = &self.trusted { let content = std::fs::read_to_string(&wdirenv)?; let mut hasher = DefaultHasher::new(); @@ -50,7 +46,8 @@ impl DirectorySpecificEnvironment { )) })?); } - return Err(ShellError::untagged_runtime_error("Found untrusted .nu-env file in this directory. Run 'autoenv trust' and restart nushell to allow it. This needs to be done after each change to the file.")); + 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.", wdirenv, wdirenv.parent().unwrap_or_else(|| &Path::new(""))))); } Err(ShellError::untagged_runtime_error("No trusted directories")) } @@ -64,12 +61,16 @@ impl DirectorySpecificEnvironment { while let Some(wdir) = working_dir { let wdirenv = wdir.join(".nu-env"); if wdirenv.exists() { - let toml_doc = self.toml_if_directory_is_trusted(wdirenv)?; + let toml_doc = self.toml_if_directory_is_trusted(&wdirenv)?; toml_doc .get("env") - .ok_or_else(|| Error::new(ErrorKind::InvalidData, "env section missing in .nu-env"))? + .ok_or_else(|| { + Error::new(ErrorKind::InvalidData, format!("[env] section missing in {:?}", wdirenv)) + })? .as_table() - .ok_or_else(|| Error::new(ErrorKind::InvalidData, "malformed env section in .nu-env"))? + .ok_or_else(|| { + Error::new(ErrorKind::InvalidData, format!("[env] section malformed in {:?}", wdirenv)) + })? .iter() .for_each(|(dir_env_key, dir_env_val)| { let dir_env_val: EnvVal = dir_env_val.as_str().unwrap().into(); diff --git a/crates/nu-cli/src/env/environment_syncer.rs b/crates/nu-cli/src/env/environment_syncer.rs index 28d8cf01c9..491de7b71f 100644 --- a/crates/nu-cli/src/env/environment_syncer.rs +++ b/crates/nu-cli/src/env/environment_syncer.rs @@ -3,7 +3,6 @@ use crate::data::config::{Conf, NuConfig}; use crate::env::environment::{Env, Environment}; use parking_lot::Mutex; use std::sync::Arc; -use nu_errors::ShellError; use nu_source::Text; pub struct EnvironmentSyncer {