diff --git a/crates/nu-cli/src/commands/path/basename.rs b/crates/nu-cli/src/commands/path/basename.rs index 59210d41d7..930c17a6f2 100644 --- a/crates/nu-cli/src/commands/path/basename.rs +++ b/crates/nu-cli/src/commands/path/basename.rs @@ -27,8 +27,9 @@ impl WholeStreamCommand for PathBasename { args: CommandArgs, registry: &CommandRegistry, ) -> Result { + let tag = args.call_info.name_tag.clone(); let (DefaultArguments { rest }, input) = args.process(®istry).await?; - operate(input, rest, &action).await + operate(input, rest, &action, tag.span).await } fn examples(&self) -> Vec { diff --git a/crates/nu-cli/src/commands/path/exists.rs b/crates/nu-cli/src/commands/path/exists.rs index 9fb20d74d1..0b0aed80ce 100644 --- a/crates/nu-cli/src/commands/path/exists.rs +++ b/crates/nu-cli/src/commands/path/exists.rs @@ -26,8 +26,9 @@ impl WholeStreamCommand for PathExists { args: CommandArgs, registry: &CommandRegistry, ) -> Result { + let tag = args.call_info.name_tag.clone(); let (DefaultArguments { rest }, input) = args.process(®istry).await?; - operate(input, rest, &action).await + operate(input, rest, &action, tag.span).await } fn examples(&self) -> Vec { diff --git a/crates/nu-cli/src/commands/path/expand.rs b/crates/nu-cli/src/commands/path/expand.rs index 7d75bcfb24..75ae5d211d 100644 --- a/crates/nu-cli/src/commands/path/expand.rs +++ b/crates/nu-cli/src/commands/path/expand.rs @@ -26,8 +26,9 @@ impl WholeStreamCommand for PathExpand { args: CommandArgs, registry: &CommandRegistry, ) -> Result { + let tag = args.call_info.name_tag.clone(); let (DefaultArguments { rest }, input) = args.process(®istry).await?; - operate(input, rest, &action).await + operate(input, rest, &action, tag.span).await } fn examples(&self) -> Vec { diff --git a/crates/nu-cli/src/commands/path/extension.rs b/crates/nu-cli/src/commands/path/extension.rs index 0a43144cce..2e99c88a01 100644 --- a/crates/nu-cli/src/commands/path/extension.rs +++ b/crates/nu-cli/src/commands/path/extension.rs @@ -27,8 +27,9 @@ impl WholeStreamCommand for PathExtension { args: CommandArgs, registry: &CommandRegistry, ) -> Result { + let tag = args.call_info.name_tag.clone(); let (DefaultArguments { rest }, input) = args.process(®istry).await?; - operate(input, rest, &action).await + operate(input, rest, &action, tag.span).await } fn examples(&self) -> Vec { diff --git a/crates/nu-cli/src/commands/path/mod.rs b/crates/nu-cli/src/commands/path/mod.rs index a088cac56e..55550e0f7d 100644 --- a/crates/nu-cli/src/commands/path/mod.rs +++ b/crates/nu-cli/src/commands/path/mod.rs @@ -8,6 +8,7 @@ mod r#type; use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{ColumnPath, Primitive, ReturnSuccess, ShellTypeName, UntaggedValue, Value}; +use nu_source::Span; use std::path::Path; pub use basename::PathBasename; @@ -22,7 +23,7 @@ struct DefaultArguments { rest: Vec, } -fn handle_value(action: &F, v: &Value) -> Result +fn handle_value(action: &F, v: &Value, span: Span) -> Result where F: Fn(&Path) -> UntaggedValue + Send + 'static, { @@ -32,9 +33,11 @@ where | UntaggedValue::Primitive(Primitive::Line(s)) => action(s.as_ref()).into_value(v.tag()), other => { let got = format!("got {}", other.type_name()); - return Err(ShellError::labeled_error( + return Err(ShellError::labeled_error_with_secondary( "value is not string or path", got, + span, + "originates from here".to_string(), v.tag().span, )); } @@ -46,6 +49,7 @@ async fn operate( input: crate::InputStream, paths: Vec, action: &'static F, + span: Span, ) -> Result where F: Fn(&Path) -> UntaggedValue + Send + Sync + 'static, @@ -53,14 +57,14 @@ where Ok(input .map(move |v| { if paths.is_empty() { - ReturnSuccess::value(handle_value(&action, &v)?) + ReturnSuccess::value(handle_value(&action, &v, span)?) } else { let mut ret = v; for path in &paths { ret = ret.swap_data_by_column_path( path, - Box::new(move |old| handle_value(&action, &old)), + Box::new(move |old| handle_value(&action, &old, span)), )?; } diff --git a/crates/nu-cli/src/commands/path/type.rs b/crates/nu-cli/src/commands/path/type.rs index 8d188abd52..9b1b019a46 100644 --- a/crates/nu-cli/src/commands/path/type.rs +++ b/crates/nu-cli/src/commands/path/type.rs @@ -27,8 +27,9 @@ impl WholeStreamCommand for PathType { args: CommandArgs, registry: &CommandRegistry, ) -> Result { + let tag = args.call_info.name_tag.clone(); let (DefaultArguments { rest }, input) = args.process(®istry).await?; - operate(input, rest, &action).await + operate(input, rest, &action, tag.span).await } fn examples(&self) -> Vec {