diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 8611517e4..7a828aca5 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -52,7 +52,7 @@ impl Command for Select { fn select(span: Span, columns: Vec, input: Value) -> Result { if columns.is_empty() { - return Err(ShellError::CantFindColumn(span)); + return Err(ShellError::CantFindColumn(span, input.span()?)); } match input { diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index 405f0cc6d..1329205c4 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -99,7 +99,10 @@ pub enum ShellError { #[error("Cannot find column")] #[diagnostic(code(nu::shell::column_not_found), url(docsrs))] - CantFindColumn(#[label = "cannot find column"] Span), + CantFindColumn( + #[label = "cannot find column"] Span, + #[label = "value originates here"] Span, + ), #[error("External command")] #[diagnostic(code(nu::shell::external_command), url(docsrs))] diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index c2e9b3080..e83bbee15 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -292,7 +292,8 @@ impl Value { val: column_name, span: origin_span, } => match &mut current { - Value::Record { cols, vals, .. } => { + Value::Record { cols, vals, span } => { + let span = *span; let mut found = false; for col in cols.iter().zip(vals.iter()) { if col.0 == column_name { @@ -303,19 +304,23 @@ impl Value { } if !found { - return Err(ShellError::CantFindColumn(*origin_span)); + return Err(ShellError::CantFindColumn(*origin_span, span)); } } Value::List { vals, span } => { let mut output = vec![]; for val in vals { - if let Value::Record { cols, vals, .. } = val { - for col in cols.iter().enumerate() { - if col.1 == column_name { - output.push(vals[col.0].clone()); - } - } - } + output.push(val.clone().follow_cell_path(&[PathMember::String { + val: column_name.clone(), + span: *origin_span, + }])?); + // if let Value::Record { cols, vals, .. } = val { + // for col in cols.iter().enumerate() { + // if col.1 == column_name { + // output.push(vals[col.0].clone()); + // } + // } + // } } current = Value::List { @@ -326,13 +331,17 @@ impl Value { Value::Stream { stream, span } => { let mut output = vec![]; for val in stream { - if let Value::Record { cols, vals, .. } = val { - for col in cols.iter().enumerate() { - if col.1 == column_name { - output.push(vals[col.0].clone()); - } - } - } + output.push(val.clone().follow_cell_path(&[PathMember::String { + val: column_name.clone(), + span: *origin_span, + }])?); + // if let Value::Record { cols, vals, .. } = val { + // for col in cols.iter().enumerate() { + // if col.1 == column_name { + // output.push(vals[col.0].clone()); + // } + // } + // } } current = Value::List {