mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
Attempt at fixing get
command panic.
If possible matches are not found then check if the passed in `obj` parameter is a `string` or a `path`, if so then return it. I am not sure this is the right fix, but I figured I would make an attempt and get a conversation started about it.
This commit is contained in:
parent
04854d5d99
commit
f3eb4fb24e
1 changed files with 20 additions and 5 deletions
|
@ -58,11 +58,14 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
|
|||
|
||||
possible_matches.sort();
|
||||
|
||||
return Err(ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
format!("did you mean '{}'?", possible_matches[0].1),
|
||||
path.tag(),
|
||||
));
|
||||
if possible_matches.len() > 0 {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Unknown column",
|
||||
format!("did you mean '{}'?", possible_matches[0].1),
|
||||
path.tag(),
|
||||
));
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +73,18 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
|
|||
}
|
||||
}
|
||||
|
||||
match obj {
|
||||
Tagged {
|
||||
item: Value::Primitive(Primitive::String(_)),
|
||||
..
|
||||
} => current = Some(obj),
|
||||
Tagged {
|
||||
item: Value::Primitive(Primitive::Path(_)),
|
||||
..
|
||||
} => current = Some(obj),
|
||||
_ => {}
|
||||
};
|
||||
|
||||
match current {
|
||||
Some(v) => Ok(v.clone()),
|
||||
None => Ok(Value::nothing().tagged(obj.tag)),
|
||||
|
|
Loading…
Reference in a new issue