From 83d82a09b21bbf09e9be84aa292e2f626a697526 Mon Sep 17 00:00:00 2001 From: Jonathan Rothberg Date: Sun, 29 Sep 2019 14:43:39 -0700 Subject: [PATCH] Better handling of unexpected error case. --- src/commands/post.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/commands/post.rs b/src/commands/post.rs index 9d08bd3a3a..5a77afd14b 100644 --- a/src/commands/post.rs +++ b/src/commands/post.rs @@ -175,16 +175,25 @@ fn get_headers(call_info: &CallInfo) -> Result, ShellError> { fn extract_header_value(call_info: &CallInfo, key: &str) -> Result, ShellError> { if call_info.args.has(key) { - let val = match call_info.args.get(key) { + let tagged = call_info.args.get(key); + let val = match tagged { Some(Tagged { item: Value::Primitive(Primitive::String(s)), .. }) => s.clone(), + Some(Tagged { tag, .. }) => { + return Err(ShellError::labeled_error( + format!("{} not in expected format. Expected string.", key), + "post error", + tag, + )); + } _ => { - return Err(ShellError::string(format!( - "{} not in expected format. Expected string.", - key - ))); + return Err(ShellError::labeled_error( + format!("{} not in expected format. Expected string.", key), + "post error", + Tag::unknown(), + )); } }; return Ok(Some(val));