Merge pull request #777 from JonnyWalker81/fix-get-panic

Attempt at fixing `get` command panic.
This commit is contained in:
Andrés N. Robalino 2019-10-03 14:02:51 -05:00 committed by GitHub
commit 3c6ee63e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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