diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index ae81a9dbb..99d67650a 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -632,24 +632,28 @@ impl Value { } Value::List { vals, span } => { let mut output = vec![]; + let mut hasvalue = false; + let mut temp: Result = Err(ShellError::NotFound(*span)); for val in vals { - output.push(val.clone().follow_cell_path(&[PathMember::String { + temp = 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()); - // } - // } - // } + }]); + if let Ok(result) = temp.clone() { + hasvalue = true; + output.push(result); + } else { + output.push(Value::Nothing { span: *span }); + } + } + if hasvalue { + current = Value::List { + vals: output, + span: *span, + }; + } else { + return temp; } - - current = Value::List { - vals: output, - span: *span, - }; } Value::CustomValue { val, .. } => { current = val.follow_path_string(column_name.clone(), *origin_span)?; diff --git a/src/tests/test_table_operations.rs b/src/tests/test_table_operations.rs index 82fffc0a7..b6a6ccb49 100644 --- a/src/tests/test_table_operations.rs +++ b/src/tests/test_table_operations.rs @@ -1,4 +1,4 @@ -use crate::tests::{fail_test, run_test, TestResult}; +use crate::tests::{run_test, TestResult}; #[test] fn cell_path_subexpr1() -> TestResult { @@ -153,10 +153,11 @@ fn update_cell_path_1() -> TestResult { } #[test] -fn missing_column_error() -> TestResult { - fail_test( - r#"([([[name, size]; [ABC, 10], [DEF, 20]]).1, ([[name]; [HIJ]]).0]).size | table"#, - "did you mean 'name'?", +fn missing_column_fills_in_nothing() -> TestResult { + // The empty value will be replaced with $nothing when fetching a column + run_test( + r#"[ { name: ABC, size: 20 }, { name: HIJ } ].size.1 == $nothing"#, + "true", ) }