diff --git a/grovedb/src/element/query.rs b/grovedb/src/element/query.rs index 98502575..8eba0c15 100644 --- a/grovedb/src/element/query.rs +++ b/grovedb/src/element/query.rs @@ -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) = @@ -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 { @@ -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 { @@ -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 { @@ -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()), ] ); @@ -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()), ] ); @@ -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()), ] ); @@ -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()), ] ); } @@ -1158,7 +1155,7 @@ mod tests { QueryOptions::default(), QueryPathKeyElementTrioResultType, None, - grove_version + grove_version, ) .unwrap() .expect("expected successful get_query") @@ -1173,7 +1170,7 @@ mod tests { vec![TEST_LEAF.to_vec()], b"c".to_vec(), Element::new_item(b"ayyc".to_vec()) - ) + ), ] ); } @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/grovedb/src/error.rs b/grovedb/src/error.rs index 92343935..4446f4ab 100644 --- a/grovedb/src/error.rs +++ b/grovedb/src/error.rs @@ -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}")] diff --git a/grovedb/src/operations/delete/mod.rs b/grovedb/src/operations/delete/mod.rs index 68f964ba..fb81532b 100644 --- a/grovedb/src/operations/delete/mod.rs +++ b/grovedb/src/operations/delete/mod.rs @@ -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 @@ -902,7 +902,7 @@ mod tests { grove_version ) .unwrap(), - Err(Error::PathParentLayerNotFound(_)) + Err(Error::InvalidParentLayerPath(_)) )); transaction.commit().expect("cannot commit transaction"); assert!(matches!( @@ -1024,7 +1024,7 @@ mod tests { grove_version ) .unwrap(), - Err(Error::PathParentLayerNotFound(_)) + Err(Error::InvalidParentLayerPath(_)) )); assert!(matches!( @@ -1145,7 +1145,7 @@ mod tests { grove_version ) .unwrap(), - Err(Error::PathParentLayerNotFound(_)) + Err(Error::InvalidParentLayerPath(_)) )); assert!(matches!( @@ -1239,7 +1239,7 @@ mod tests { grove_version ) .unwrap(), - Err(Error::PathParentLayerNotFound(_)) + Err(Error::InvalidParentLayerPath(_)) )); transaction.commit().expect("cannot commit transaction"); assert!(matches!( @@ -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) @@ -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) diff --git a/grovedb/src/operations/get/mod.rs b/grovedb/src/operations/get/mod.rs index f23f4335..41830873 100644 --- a/grovedb/src/operations/get/mod.rs +++ b/grovedb/src/operations/get/mod.rs @@ -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) => { @@ -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) @@ -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), } ); diff --git a/grovedb/src/tests/mod.rs b/grovedb/src/tests/mod.rs index b0540e72..69fb55f3 100644 --- a/grovedb/src/tests/mod.rs +++ b/grovedb/src/tests/mod.rs @@ -3929,7 +3929,7 @@ mod tests { assert!(elem_result.is_err()); assert!(matches!( elem_result, - Err(Error::PathParentLayerNotFound(..)) + Err(Error::InvalidParentLayerPath(..)) )); }