mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:15:14 +02:00
Better error messages.
This commit is contained in:
@ -56,6 +56,26 @@ pub fn get_column_path(
|
||||
obj.tag(),
|
||||
path,
|
||||
Box::new(move |(obj_source, column_path_tried)| {
|
||||
match obj_source {
|
||||
Value::Table(rows) => {
|
||||
let total = rows.len();
|
||||
let end_tag = match fields.iter().nth_back(if fields.len() > 2 { 1 } else { 0 })
|
||||
{
|
||||
Some(last_field) => last_field.tag(),
|
||||
None => column_path_tried.tag(),
|
||||
};
|
||||
|
||||
return ShellError::labeled_error_with_secondary(
|
||||
"Row not found",
|
||||
format!("There isn't a row indexed at '{}'", **column_path_tried),
|
||||
column_path_tried.tag(),
|
||||
format!("The table only has {} rows (0..{})", total, total - 1),
|
||||
end_tag,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match did_you_mean(&obj_source, &column_path_tried) {
|
||||
Some(suggestions) => {
|
||||
return ShellError::labeled_error(
|
||||
|
@ -459,11 +459,10 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This is basically a legacy construct, I think
|
||||
pub fn data_descriptors(&self) -> Vec<String> {
|
||||
match self {
|
||||
Value::Primitive(_) => vec![],
|
||||
Value::Row(o) => o
|
||||
Value::Row(columns) => columns
|
||||
.entries
|
||||
.keys()
|
||||
.into_iter()
|
||||
@ -534,12 +533,9 @@ impl Value {
|
||||
) -> Result<Option<Tagged<&Value>>, ShellError> {
|
||||
let mut current = self;
|
||||
for p in path {
|
||||
let value = if p.chars().all(char::is_numeric) {
|
||||
current.get_data_by_index(p.chars().fold(0 as usize, |acc, c| {
|
||||
c.to_digit(10).unwrap_or(0) as usize + acc
|
||||
}))
|
||||
} else {
|
||||
current.get_data_by_key(p)
|
||||
let value = match p.item().parse::<usize>() {
|
||||
Ok(number) => current.get_data_by_index(number),
|
||||
Err(_) => current.get_data_by_key(p),
|
||||
};
|
||||
|
||||
match value {
|
||||
|
@ -98,8 +98,6 @@ impl Str {
|
||||
value.tag(),
|
||||
&f,
|
||||
Box::new(move |(obj_source, column_path_tried)| {
|
||||
//let fields = f.clone();
|
||||
|
||||
match did_you_mean(&obj_source, &column_path_tried) {
|
||||
Some(suggestions) => {
|
||||
return ShellError::labeled_error(
|
||||
|
Reference in New Issue
Block a user