Skip to content

Commit

Permalink
remove redundant error
Browse files Browse the repository at this point in the history
  • Loading branch information
fominok committed Oct 29, 2024
1 parent 15b3034 commit 6af542b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 55 deletions.
57 changes: 27 additions & 30 deletions grovedb/src/element/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,16 @@ impl Element {
if !item.is_range() {
// this is a query on a key
if let QueryItem::Key(key) = item {
let subtree = cost_return_on_error!(
&mut cost,
util::open_transactional_merk_at_path(
storage,
subtree_path,
transaction,
None,
grove_version
)
);
let element_res =
Element::get(&subtree, key, query_options.allow_cache, grove_version)
.unwrap_add_cost(&mut cost);
let element_res = util::open_transactional_merk_at_path(
storage,
subtree_path,
transaction,
None,
grove_version,
)
.flat_map_ok(|s| Element::get(&s, key, query_options.allow_cache, grove_version))
.unwrap_add_cost(&mut cost);

match element_res {
Ok(element) => {
let (subquery_path, subquery) =
Expand Down Expand Up @@ -782,7 +779,7 @@ impl Element {
Err(e) => {
if !query_options.error_if_intermediate_path_tree_not_present {
match e {
Error::PathParentLayerNotFound(_) => Ok(()),
Error::InvalidParentLayerPath(_) => Ok(()),
_ => Err(e),
}
} else {
Expand All @@ -795,7 +792,7 @@ impl Element {
Err(e) => {
if !query_options.error_if_intermediate_path_tree_not_present {
match e {
Error::PathParentLayerNotFound(_) => Ok(()),
Error::InvalidParentLayerPath(_) => Ok(()),
_ => Err(e),
}
} else {
Expand Down Expand Up @@ -862,7 +859,7 @@ impl Element {
Err(e) => {
if !query_options.error_if_intermediate_path_tree_not_present {
match e {
Error::PathKeyNotFound(_) | Error::PathParentLayerNotFound(_) => (),
Error::PathKeyNotFound(_) | Error::InvalidParentLayerPath(_) => (),
_ => return Err(e).wrap_with_cost(cost),
}
} else {
Expand Down Expand Up @@ -1022,13 +1019,13 @@ mod tests {
&query,
QueryOptions::default(),
None,
grove_version
grove_version,
)
.unwrap()
.expect("expected successful get_query"),
vec![
Element::new_item(b"ayya".to_vec()),
Element::new_item(b"ayyc".to_vec())
Element::new_item(b"ayyc".to_vec()),
]
);

Expand All @@ -1043,14 +1040,14 @@ mod tests {
&query,
QueryOptions::default(),
None,
grove_version
grove_version,
)
.unwrap()
.expect("expected successful get_query"),
vec![
Element::new_item(b"ayya".to_vec()),
Element::new_item(b"ayyb".to_vec()),
Element::new_item(b"ayyc".to_vec())
Element::new_item(b"ayyc".to_vec()),
]
);

Expand All @@ -1065,14 +1062,14 @@ mod tests {
&query,
QueryOptions::default(),
None,
grove_version
grove_version,
)
.unwrap()
.expect("expected successful get_query"),
vec![
Element::new_item(b"ayyb".to_vec()),
Element::new_item(b"ayyc".to_vec()),
Element::new_item(b"ayyd".to_vec())
Element::new_item(b"ayyd".to_vec()),
]
);

Expand All @@ -1088,14 +1085,14 @@ mod tests {
&query,
QueryOptions::default(),
None,
grove_version
grove_version,
)
.unwrap()
.expect("expected successful get_query"),
vec![
Element::new_item(b"ayya".to_vec()),
Element::new_item(b"ayyb".to_vec()),
Element::new_item(b"ayyc".to_vec())
Element::new_item(b"ayyc".to_vec()),
]
);
}
Expand Down Expand Up @@ -1158,7 +1155,7 @@ mod tests {
QueryOptions::default(),
QueryPathKeyElementTrioResultType,
None,
grove_version
grove_version,
)
.unwrap()
.expect("expected successful get_query")
Expand All @@ -1173,7 +1170,7 @@ mod tests {
vec![TEST_LEAF.to_vec()],
b"c".to_vec(),
Element::new_item(b"ayyc".to_vec())
)
),
]
);
}
Expand Down Expand Up @@ -1525,7 +1522,7 @@ mod tests {
.expect("expected successful get_query");
assert_eq!(
elements.to_key_elements(),
vec![(b"c".to_vec(), Element::new_item(b"ayyc".to_vec())),]
vec![(b"c".to_vec(), Element::new_item(b"ayyc".to_vec()))]
);
assert_eq!(skipped, 0);

Expand All @@ -1549,7 +1546,7 @@ mod tests {
elements.to_key_elements(),
vec![
(b"a".to_vec(), Element::new_item(b"ayya".to_vec())),
(b"b".to_vec(), Element::new_item(b"ayyb".to_vec()))
(b"b".to_vec(), Element::new_item(b"ayyb".to_vec())),
]
);
assert_eq!(skipped, 0);
Expand All @@ -1570,7 +1567,7 @@ mod tests {
elements.to_key_elements(),
vec![
(b"b".to_vec(), Element::new_item(b"ayyb".to_vec())),
(b"c".to_vec(), Element::new_item(b"ayyc".to_vec()))
(b"c".to_vec(), Element::new_item(b"ayyc".to_vec())),
]
);
assert_eq!(skipped, 1);
Expand All @@ -1596,7 +1593,7 @@ mod tests {
elements.to_key_elements(),
vec![
(b"b".to_vec(), Element::new_item(b"ayyb".to_vec())),
(b"a".to_vec(), Element::new_item(b"ayya".to_vec()))
(b"a".to_vec(), Element::new_item(b"ayya".to_vec())),
]
);
assert_eq!(skipped, 1);
Expand Down
4 changes: 0 additions & 4 deletions grovedb/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ pub enum Error {
/// isn't there
#[error("path not found: {0}")]
PathNotFound(String),
/// The path not found could represent a valid query, just where the parent
/// path merk isn't there
#[error("path parent layer not found: {0}")]
PathParentLayerNotFound(String),

/// The path's item by key referenced was not found
#[error("corrupted referenced path key not found: {0}")]
Expand Down
14 changes: 7 additions & 7 deletions grovedb/src/operations/delete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));
// assert_eq!(db.subtrees.len().unwrap(), 3); // TEST_LEAF, ANOTHER_TEST_LEAF
// TEST_LEAF.key4 stay
Expand Down Expand Up @@ -902,7 +902,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));
transaction.commit().expect("cannot commit transaction");
assert!(matches!(
Expand Down Expand Up @@ -1024,7 +1024,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));

assert!(matches!(
Expand Down Expand Up @@ -1145,7 +1145,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));

assert!(matches!(
Expand Down Expand Up @@ -1239,7 +1239,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));
transaction.commit().expect("cannot commit transaction");
assert!(matches!(
Expand Down Expand Up @@ -1324,7 +1324,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));
assert!(matches!(
db.get([TEST_LEAF].as_ref(), b"key1", None, grove_version)
Expand Down Expand Up @@ -1727,7 +1727,7 @@ mod tests {
grove_version
)
.unwrap(),
Err(Error::PathParentLayerNotFound(_))
Err(Error::InvalidParentLayerPath(_))
));
let key1_tree = db
.get([TEST_LEAF].as_ref(), b"key1", None, grove_version)
Expand Down
15 changes: 2 additions & 13 deletions grovedb/src/operations/get/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl GroveDb {
grove_version
)
.map_err(|e| match e {
Error::PathParentLayerNotFound(p) => {
Error::InvalidParentLayerPath(p) => {
Error::CorruptedReferencePathParentLayerNotFound(p)
}
Error::PathKeyNotFound(p) => {
Expand Down Expand Up @@ -281,12 +281,6 @@ impl GroveDb {
let merk_to_get_from = cost_return_on_error!(
&mut cost,
self.open_transactional_merk_at_path(path, transaction, None, grove_version)
.map_err(|e| match e {
Error::InvalidParentLayerPath(s) => {
Error::PathParentLayerNotFound(s)
}
_ => e,
})
);

Element::get(&merk_to_get_from, key, allow_cache, grove_version).add_cost(cost)
Expand All @@ -304,17 +298,12 @@ impl GroveDb {
let mut cost = OperationCost::default();
let merk_result = self
.open_transactional_merk_at_path(path, transaction, None, grove_version)
.map_err(|e| match e {
Error::InvalidParentLayerPath(s) => Error::PathParentLayerNotFound(s),
_ => e,
})
.unwrap_add_cost(&mut cost);
let merk = cost_return_on_error_no_add!(
cost,
match merk_result {
Ok(result) => Ok(Some(result)),
Err(Error::PathParentLayerNotFound(_)) | Err(Error::InvalidParentLayerPath(_)) =>
Ok(None),
Err(Error::InvalidParentLayerPath(_)) => Ok(None),
Err(e) => Err(e),
}
);
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3929,7 +3929,7 @@ mod tests {
assert!(elem_result.is_err());
assert!(matches!(
elem_result,
Err(Error::PathParentLayerNotFound(..))
Err(Error::InvalidParentLayerPath(..))
));
}

Expand Down

0 comments on commit 6af542b

Please sign in to comment.