mirror of
https://github.com/nushell/nushell
synced 2024-12-30 15:03:25 +00:00
Error on missing column during cell path
This commit is contained in:
parent
6e92812cdf
commit
1a15f30eb8
3 changed files with 30 additions and 18 deletions
|
@ -52,7 +52,7 @@ impl Command for Select {
|
||||||
|
|
||||||
fn select(span: Span, columns: Vec<CellPath>, input: Value) -> Result<Value, ShellError> {
|
fn select(span: Span, columns: Vec<CellPath>, input: Value) -> Result<Value, ShellError> {
|
||||||
if columns.is_empty() {
|
if columns.is_empty() {
|
||||||
return Err(ShellError::CantFindColumn(span));
|
return Err(ShellError::CantFindColumn(span, input.span()?));
|
||||||
}
|
}
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
|
|
|
@ -99,7 +99,10 @@ pub enum ShellError {
|
||||||
|
|
||||||
#[error("Cannot find column")]
|
#[error("Cannot find column")]
|
||||||
#[diagnostic(code(nu::shell::column_not_found), url(docsrs))]
|
#[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")]
|
#[error("External command")]
|
||||||
#[diagnostic(code(nu::shell::external_command), url(docsrs))]
|
#[diagnostic(code(nu::shell::external_command), url(docsrs))]
|
||||||
|
|
|
@ -292,7 +292,8 @@ impl Value {
|
||||||
val: column_name,
|
val: column_name,
|
||||||
span: origin_span,
|
span: origin_span,
|
||||||
} => match &mut current {
|
} => match &mut current {
|
||||||
Value::Record { cols, vals, .. } => {
|
Value::Record { cols, vals, span } => {
|
||||||
|
let span = *span;
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for col in cols.iter().zip(vals.iter()) {
|
for col in cols.iter().zip(vals.iter()) {
|
||||||
if col.0 == column_name {
|
if col.0 == column_name {
|
||||||
|
@ -303,19 +304,23 @@ impl Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return Err(ShellError::CantFindColumn(*origin_span));
|
return Err(ShellError::CantFindColumn(*origin_span, span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::List { vals, span } => {
|
Value::List { vals, span } => {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for val in vals {
|
for val in vals {
|
||||||
if let Value::Record { cols, vals, .. } = val {
|
output.push(val.clone().follow_cell_path(&[PathMember::String {
|
||||||
for col in cols.iter().enumerate() {
|
val: column_name.clone(),
|
||||||
if col.1 == column_name {
|
span: *origin_span,
|
||||||
output.push(vals[col.0].clone());
|
}])?);
|
||||||
}
|
// 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 {
|
current = Value::List {
|
||||||
|
@ -326,13 +331,17 @@ impl Value {
|
||||||
Value::Stream { stream, span } => {
|
Value::Stream { stream, span } => {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for val in stream {
|
for val in stream {
|
||||||
if let Value::Record { cols, vals, .. } = val {
|
output.push(val.clone().follow_cell_path(&[PathMember::String {
|
||||||
for col in cols.iter().enumerate() {
|
val: column_name.clone(),
|
||||||
if col.1 == column_name {
|
span: *origin_span,
|
||||||
output.push(vals[col.0].clone());
|
}])?);
|
||||||
}
|
// 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 {
|
current = Value::List {
|
||||||
|
|
Loading…
Reference in a new issue