Better handling of unexpected error case.

This commit is contained in:
Jonathan Rothberg 2019-09-29 14:43:39 -07:00
parent ff92123d93
commit 83d82a09b2

View File

@ -175,16 +175,25 @@ fn get_headers(call_info: &CallInfo) -> Result<Vec<HeaderKind>, ShellError> {
fn extract_header_value(call_info: &CallInfo, key: &str) -> Result<Option<String>, 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));