diff --git a/crates/nu-command/tests/commands/get.rs b/crates/nu-command/tests/commands/get.rs index d8a823089..6f38df402 100644 --- a/crates/nu-command/tests/commands/get.rs +++ b/crates/nu-command/tests/commands/get.rs @@ -176,12 +176,7 @@ fn errors_fetching_by_column_using_a_number() { "# )); - assert!(actual - .err - .contains("Data cannot be accessed with a cell path"),); - assert!(actual - .err - .contains("record<0: string> doesn't support cell paths"),); + assert!(actual.err.contains("Type mismatch"),); }) } diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index 039d33958..0f50e7d60 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -60,6 +60,19 @@ pub enum ShellError { #[diagnostic(code(nu::shell::type_mismatch), url(docsrs))] TypeMismatch(String, #[label = "needs {0}"] Span), + /// A command received an argument of the wrong type. + /// + /// ## Resolution + /// + /// Convert the argument type before passing it in, or change the command to accept the type. + #[error("Type mismatch")] + #[diagnostic(code(nu::shell::type_mismatch), url(docsrs))] + TypeMismatchGenericMessage { + err_message: String, + #[label = "{err_message}"] + span: Span, + }, + /// This value cannot be used with this operator. /// /// ## Resolution diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 4651d0fa2..79f6554da 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -666,10 +666,9 @@ impl Value { current = val.follow_path_int(*count, *origin_span)?; } x => { - return Err(ShellError::IncompatiblePathAccess( - format!("{}", x.get_type()), - *origin_span, - )) + return Err(ShellError::TypeMismatchGenericMessage { + err_message: format!("Can't access {} values with a row index. Try specifying a column name instead", x.get_type().to_shape()), + span: *origin_span, }) } } }