Fast and robust atproto CAR file processing in rust
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

unwrap -> error by changing into -> try_into

phil 5b9dd12d 3d85059c

+12 -11
+12 -11
src/walk.rs
··· 17 17 RecordFailedProcessing(Box<dyn Error>), 18 18 #[error("Action node error: {0}")] 19 19 ActionNode(#[from] ActionNodeError), 20 - #[error("RKey was not utf-8")] 21 - EntryRkeyNotUtf8(#[from] std::string::FromUtf8Error), 22 20 #[error("Process failed: {0}")] 23 21 ProcessFailed(E), 24 22 } ··· 27 25 pub enum ActionNodeError { 28 26 #[error("Failed to compute an rkey due to invalid prefix_len")] 29 27 EntryPrefixOutOfbounds, 28 + #[error("RKey was not utf-8")] 29 + EntryRkeyNotUtf8(#[from] std::string::FromUtf8Error), 30 30 } 31 31 32 32 #[derive(Debug)] ··· 145 145 Record { rkey: String, cid: Cid }, 146 146 } 147 147 148 - impl From<&Node> for ActionNode { 149 - fn from(node: &Node) -> Self { 148 + impl TryFrom<&Node> for ActionNode { 149 + type Error = ActionNodeError; 150 + 151 + fn try_from(node: &Node) -> Result<Self, Self::Error> { 150 152 let left_tree = node.left.as_ref().map(Into::into); 151 153 152 154 let mut entries = vec![]; ··· 155 157 let mut rkey = vec![]; 156 158 let pre_checked = prefix 157 159 .get(..entry.prefix_len) 158 - .ok_or(ActionNodeError::EntryPrefixOutOfbounds) 159 - .unwrap(); // TODO has to be try_from 160 + .ok_or(ActionNodeError::EntryPrefixOutOfbounds)?; 160 161 rkey.extend_from_slice(pre_checked); 161 162 rkey.extend_from_slice(&entry.keysuffix); 162 163 prefix = rkey.clone(); 163 164 164 165 entries.push(ActionEntry { 165 - rkey: String::from_utf8(rkey).unwrap(), // TODO this has to be try_from 166 + rkey: String::from_utf8(rkey)?, // TODO this has to be try_from 166 167 record: (&entry.value).into(), 167 168 tree: entry.tree.as_ref().map(Into::into), 168 169 }); 169 170 } 170 171 171 - ActionNode { left_tree, entries } 172 + Ok(ActionNode { left_tree, entries }) 172 173 } 173 174 } 174 175 ··· 217 218 current_node.found(cid); 218 219 219 220 // queue up work on the found node next 220 - self.stack.push((&node).into()); 221 + self.stack.push((&node).try_into()?); 221 222 } 222 223 Need::Record { rkey, cid } => { 223 224 log::trace!("need record {cid:?}"); ··· 303 304 left: None, 304 305 entries: vec![], 305 306 }; 306 - let action_node: ActionNode = (&node).into(); 307 + let action_node: ActionNode = (&node).try_into().unwrap(); 307 308 assert_eq!(action_node.next(), None); 308 309 } 309 310 ··· 313 314 left: Some(cid1()), 314 315 entries: vec![], 315 316 }; 316 - let action_node: ActionNode = (&node).into(); 317 + let action_node: ActionNode = (&node).try_into().unwrap(); 317 318 assert_eq!(action_node.next(), Some(Need::Node(cid1()))); 318 319 } 319 320