Add support for new link type in return-value parsing
This commit is contained in:
parent
21d758d635
commit
8de5bf93be
2 changed files with 35 additions and 2 deletions
|
@ -23,6 +23,9 @@ generate_error_module!(
|
|||
EntryHeaderWriteError => "Error while writing an entry header",
|
||||
ExistingLinkTypeWrong => "Existing link entry has wrong type",
|
||||
LinkTargetDoesNotExist => "Link target does not exist in the store",
|
||||
LinkParserError => "Link cannot be parsed",
|
||||
LinkParserFieldMissingError => "Link cannot be parsed: Field missing",
|
||||
LinkParserFieldTypeError => "Link cannot be parsed: Field type wrong",
|
||||
InternalConversionError => "Error while converting values internally",
|
||||
InvalidUri => "URI is not valid",
|
||||
StoreReadError => "Store read error",
|
||||
|
|
|
@ -494,19 +494,49 @@ fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<LinkIter> {
|
|||
}
|
||||
};
|
||||
|
||||
if !links.iter().all(|l| is_match!(*l, Value::String(_))) {
|
||||
debug!("At least one of the Values which were expected in the Array of links is a non-String!");
|
||||
if !links.iter().all(|l| is_match!(*l, Value::String(_)) || is_match!(*l, Value::Table(_))) {
|
||||
debug!("At least one of the Values which were expected in the Array of links is not a String or a Table!");
|
||||
debug!("Generating LinkError");
|
||||
return Err(LEK::ExistingLinkTypeWrong.into());
|
||||
}
|
||||
|
||||
let links : Vec<Link> = try!(links.into_iter()
|
||||
.map(|link| {
|
||||
debug!("Matching the link: {:?}", link);
|
||||
match link {
|
||||
Value::String(s) => StoreId::new_baseless(PathBuf::from(s))
|
||||
.map_err_into(LEK::StoreIdError)
|
||||
.map(|s| Link::Id { link: s })
|
||||
,
|
||||
Value::Table(mut tab) => {
|
||||
debug!("Destructuring table");
|
||||
if !tab.contains_key("link")
|
||||
|| !tab.contains_key("annotation") {
|
||||
debug!("Things missing... returning Error instance");
|
||||
Err(LEK::LinkParserError.into_error())
|
||||
} else {
|
||||
let link = try!(tab.remove("link")
|
||||
.ok_or(LEK::LinkParserFieldMissingError.into_error()));
|
||||
|
||||
let anno = try!(tab.remove("annotation")
|
||||
.ok_or(LEK::LinkParserFieldMissingError.into_error()));
|
||||
|
||||
debug!("Ok, here we go with building a Link::Annotated");
|
||||
match (link, anno) {
|
||||
(Value::String(link), Value::String(anno)) => {
|
||||
StoreId::new_baseless(PathBuf::from(link))
|
||||
.map_err_into(LEK::StoreIdError)
|
||||
.map(|link| {
|
||||
Link::Annotated {
|
||||
link: link,
|
||||
annotation: anno,
|
||||
}
|
||||
})
|
||||
},
|
||||
_ => Err(LEK::LinkParserFieldTypeError.into_error()),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue