From f3eb4fb24e0eb14cf9eb0482654533f521878b24 Mon Sep 17 00:00:00 2001 From: Jonathan Rothberg Date: Wed, 2 Oct 2019 20:16:27 -0700 Subject: [PATCH 1/2] 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. --- src/commands/get.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/commands/get.rs b/src/commands/get.rs index 930392e5d6..3b9f578e26 100644 --- a/src/commands/get.rs +++ b/src/commands/get.rs @@ -58,11 +58,14 @@ fn get_member(path: &Tagged, obj: &Tagged) -> Result 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, obj: &Tagged) -> Result 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)), From e54cd98a9cf31934773331f00acaec30bba2b4c7 Mon Sep 17 00:00:00 2001 From: Jonathan Rothberg Date: Wed, 2 Oct 2019 20:41:53 -0700 Subject: [PATCH 2/2] Put code into None case of last match. --- src/commands/get.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/commands/get.rs b/src/commands/get.rs index 3b9f578e26..afa550c72c 100644 --- a/src/commands/get.rs +++ b/src/commands/get.rs @@ -73,21 +73,20 @@ fn get_member(path: &Tagged, obj: &Tagged) -> Result 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)), + 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)), + }, } }