Errors print, but not nicely

This commit is contained in:
Sam Hedin 2020-06-23 19:19:38 +02:00
parent 595b188855
commit b85a2529e3
2 changed files with 5 additions and 32 deletions

View File

@ -34,34 +34,6 @@ impl DirectorySpecificEnvironment {
}
}
// fn toml_if_directory_is_trusted(
// &self,
// mut wdirenv: PathBuf,
// ) -> Result<toml::Value, ShellError> {
// if let Some(trusted) = &self.trusted {
// wdirenv.push(".nu-env");
// if wdirenv.exists() {
// let content = std::fs::read_to_string(&wdirenv)?;
// let mut hasher = DefaultHasher::new();
// content.hash(&mut hasher);
// if trusted.files.get(wdirenv.to_str().unwrap())
// == Some(&hasher.finish().to_string())
// {
// return Ok(content.parse::<toml::Value>().or_else(|_| {
// Err(ShellError::unexpected_eof(
// "Could not parse .nu-env file. Is it well-formed?",
// Span::default(),
// ))
// })?);
// } else {
// return Err(ShellError::unexpected_eof("Found .nu-env file in this directory, but it is not trusted. You can run 'autoenv trust' to allow it. This needs to be done after each change to the file",
// Span::default()));
// }
// }
// }
// Err(ShellError::unexpected_eof("No trusted directories", Span::default()))
// }
fn toml_if_directory_is_trusted(
&self,
wdirenv: PathBuf,
@ -78,7 +50,7 @@ impl DirectorySpecificEnvironment {
))
})?);
}
return Err(ShellError::untagged_runtime_error("Found .nu-env file in this directory, but it is not trusted. You can run 'autoenv trust' to allow it. This needs to be done after each change to the file"));
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."));
}
Err(ShellError::untagged_runtime_error("No trusted directories"))
}
@ -95,9 +67,9 @@ impl DirectorySpecificEnvironment {
let toml_doc = self.toml_if_directory_is_trusted(wdirenv)?;
toml_doc
.get("env")
.ok_or_else(|| Error::new(ErrorKind::InvalidData, "env section missing"))?
.ok_or_else(|| Error::new(ErrorKind::InvalidData, "env section missing in .nu-env"))?
.as_table()
.ok_or_else(|| Error::new(ErrorKind::InvalidData, "env section malformed"))?
.ok_or_else(|| Error::new(ErrorKind::InvalidData, "malformed env section in .nu-env"))?
.iter()
.for_each(|(dir_env_key, dir_env_val)| {
let dir_env_val: EnvVal = dir_env_val.as_str().unwrap().into();

View File

@ -4,6 +4,7 @@ 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 {
pub env: Arc<Mutex<Box<Environment>>>,
@ -46,7 +47,7 @@ impl EnvironmentSyncer {
let mut environment = self.env.lock();
if let Err(e) = environment.maintain_directory_environment() {
ctx.error(e);
crate::cli::print_err(e, &Text::from(""));
}
if environment.env().is_some() {
for (name, value) in ctx.with_host(|host| host.vars()) {