mirror of
https://github.com/nushell/nushell.git
synced 2025-05-29 14:21:45 +02:00
Errors print, but not nicely
This commit is contained in:
parent
595b188855
commit
b85a2529e3
@ -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(
|
fn toml_if_directory_is_trusted(
|
||||||
&self,
|
&self,
|
||||||
wdirenv: PathBuf,
|
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"))
|
Err(ShellError::untagged_runtime_error("No trusted directories"))
|
||||||
}
|
}
|
||||||
@ -95,9 +67,9 @@ impl DirectorySpecificEnvironment {
|
|||||||
let toml_doc = self.toml_if_directory_is_trusted(wdirenv)?;
|
let toml_doc = self.toml_if_directory_is_trusted(wdirenv)?;
|
||||||
toml_doc
|
toml_doc
|
||||||
.get("env")
|
.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()
|
.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()
|
.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().into();
|
||||||
|
3
crates/nu-cli/src/env/environment_syncer.rs
vendored
3
crates/nu-cli/src/env/environment_syncer.rs
vendored
@ -4,6 +4,7 @@ use crate::env::environment::{Env, Environment};
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
|
use nu_source::Text;
|
||||||
|
|
||||||
pub struct EnvironmentSyncer {
|
pub struct EnvironmentSyncer {
|
||||||
pub env: Arc<Mutex<Box<Environment>>>,
|
pub env: Arc<Mutex<Box<Environment>>>,
|
||||||
@ -46,7 +47,7 @@ impl EnvironmentSyncer {
|
|||||||
let mut environment = self.env.lock();
|
let mut environment = self.env.lock();
|
||||||
|
|
||||||
if let Err(e) = environment.maintain_directory_environment() {
|
if let Err(e) = environment.maintain_directory_environment() {
|
||||||
ctx.error(e);
|
crate::cli::print_err(e, &Text::from(""));
|
||||||
}
|
}
|
||||||
if environment.env().is_some() {
|
if environment.env().is_some() {
|
||||||
for (name, value) in ctx.with_host(|host| host.vars()) {
|
for (name, value) in ctx.with_host(|host| host.vars()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user