mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 08:29:07 +01:00
Merge pull request #777 from JonnyWalker81/fix-get-panic
Attempt at fixing `get` command panic.
This commit is contained in:
commit
3c6ee63e59
@ -58,11 +58,14 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
|
|||||||
|
|
||||||
possible_matches.sort();
|
possible_matches.sort();
|
||||||
|
|
||||||
return Err(ShellError::labeled_error(
|
if possible_matches.len() > 0 {
|
||||||
"Unknown column",
|
return Err(ShellError::labeled_error(
|
||||||
format!("did you mean '{}'?", possible_matches[0].1),
|
"Unknown column",
|
||||||
path.tag(),
|
format!("did you mean '{}'?", possible_matches[0].1),
|
||||||
));
|
path.tag(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,7 +75,18 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
|
|||||||
|
|
||||||
match current {
|
match current {
|
||||||
Some(v) => Ok(v.clone()),
|
Some(v) => Ok(v.clone()),
|
||||||
None => Ok(Value::nothing().tagged(obj.tag)),
|
None => match obj {
|
||||||
|
// If its None check for certain values.
|
||||||
|
Tagged {
|
||||||
|
item: Value::Primitive(Primitive::String(_)),
|
||||||
|
..
|
||||||
|
} => Ok(obj.clone()),
|
||||||
|
Tagged {
|
||||||
|
item: Value::Primitive(Primitive::Path(_)),
|
||||||
|
..
|
||||||
|
} => Ok(obj.clone()),
|
||||||
|
_ => Ok(Value::nothing().tagged(obj.tag)),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user