From 857c522808da1a08c8ff9c8702938af110c68fd7 Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Wed, 7 Feb 2024 23:22:15 +0000 Subject: [PATCH] Fix #11750: `LazyRecord` error message (#11772) # Description Makes `LazyRecord`s have the same error message as regular `Records` for `Value::follow_cell_path`. Fixes #11750. --- crates/nu-protocol/src/value/mod.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 6be79edd18..9c9a2ae2a8 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -976,7 +976,7 @@ impl Value { } // Records (and tables) are the only built-in which support column names, // so only use this message for them. - Value::Record { .. } => { + Value::Record { .. } | Value::LazyRecord { .. } => { return Err(ShellError::TypeMismatch { err_message:"Can't access record values with a row index. Try specifying a column name instead".into(), span: *origin_span, @@ -1202,9 +1202,8 @@ impl Value { } Value::LazyRecord { val, .. } => { // convert to Record first. - let mut record = val.collect()?; - record.upsert_data_at_cell_path(cell_path, new_val)?; - *self = record; + *self = val.collect()?; + self.upsert_data_at_cell_path(cell_path, new_val)?; } Value::Error { error, .. } => return Err(*error.clone()), v => { @@ -1319,9 +1318,8 @@ impl Value { } Value::LazyRecord { val, .. } => { // convert to Record first. - let mut record = val.collect()?; - record.update_data_at_cell_path(cell_path, new_val)?; - *self = record; + *self = val.collect()?; + self.update_data_at_cell_path(cell_path, new_val)?; } Value::Error { error, .. } => return Err(*error.clone()), v => { @@ -1409,10 +1407,8 @@ impl Value { } Value::LazyRecord { val, .. } => { // convert to Record first. - let mut record = val.collect()?; - record.remove_data_at_cell_path(cell_path)?; - *self = record; - Ok(()) + *self = val.collect()?; + self.remove_data_at_cell_path(cell_path) } v => Err(ShellError::CantFindColumn { col_name: col_name.clone(), @@ -1495,10 +1491,8 @@ impl Value { } Value::LazyRecord { val, .. } => { // convert to Record first. - let mut record = val.collect()?; - record.remove_data_at_cell_path(cell_path)?; - *self = record; - Ok(()) + *self = val.collect()?; + self.remove_data_at_cell_path(cell_path) } v => Err(ShellError::CantFindColumn { col_name: col_name.clone(), @@ -1624,9 +1618,8 @@ impl Value { } Value::LazyRecord { val, .. } => { // convert to Record first. - let mut record = val.collect()?; - record.insert_data_at_cell_path(cell_path, new_val, v_span)?; - *self = record; + *self = val.collect()?; + self.insert_data_at_cell_path(cell_path, new_val, v_span)?; } other => { return Err(ShellError::UnsupportedInput {