mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Make get 1
error message better (#6892)
This commit is contained in:
parent
92ab8b831b
commit
e0cc2c9112
3 changed files with 17 additions and 10 deletions
|
@ -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"),);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue