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:
Jonathan Rothberg 2019-10-02 20:16:27 -07:00
parent 04854d5d99
commit f3eb4fb24e

View file

@ -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)),