Make get 1 error message better (#6892)

This commit is contained in:
Reilly Wood 2022-10-24 18:22:57 -07:00 committed by GitHub
parent 92ab8b831b
commit e0cc2c9112
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 10 deletions

View File

@ -176,12 +176,7 @@ fn errors_fetching_by_column_using_a_number() {
"# "#
)); ));
assert!(actual assert!(actual.err.contains("Type mismatch"),);
.err
.contains("Data cannot be accessed with a cell path"),);
assert!(actual
.err
.contains("record<0: string> doesn't support cell paths"),);
}) })
} }

View File

@ -60,6 +60,19 @@ pub enum ShellError {
#[diagnostic(code(nu::shell::type_mismatch), url(docsrs))] #[diagnostic(code(nu::shell::type_mismatch), url(docsrs))]
TypeMismatch(String, #[label = "needs {0}"] Span), 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. /// This value cannot be used with this operator.
/// ///
/// ## Resolution /// ## Resolution

View File

@ -666,10 +666,9 @@ impl Value {
current = val.follow_path_int(*count, *origin_span)?; current = val.follow_path_int(*count, *origin_span)?;
} }
x => { x => {
return Err(ShellError::IncompatiblePathAccess( return Err(ShellError::TypeMismatchGenericMessage {
format!("{}", x.get_type()), err_message: format!("Can't access {} values with a row index. Try specifying a column name instead", x.get_type().to_shape()),
*origin_span, span: *origin_span, })
))
} }
} }
} }