diff --git a/crates/nu-command/tests/commands/get.rs b/crates/nu-command/tests/commands/get.rs index d8a8230891..6f38df402f 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 039d339581..0f50e7d60f 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 4651d0fa2e..79f6554daa 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, }) } } }