fork of https://github.com/tree-sitter/tree-sitter-graph

Add richer context to duplicate edge/attribute/variable errors

Changed files
+37 -28
src
execution
+37 -28
src/execution/lazy/statements.rs
··· 119 119 GraphElementKey::NodeAttribute(node, attribute.name.clone()), 120 120 self.debug_info.clone(), 121 121 ); 122 - exec.graph[node] 122 + if let Err(_) = exec.graph[node] 123 123 .attributes 124 124 .add(attribute.name.clone(), value) 125 - .map_err(|_| { 126 - ExecutionError::DuplicateAttribute(format!( 127 - "{} on {} at {} and {}", 128 - attribute.name, 129 - node, 130 - prev_debug_info.unwrap(), 131 - self.debug_info, 132 - )) 133 - })?; 125 + { 126 + return Err(ExecutionError::DuplicateAttribute(format!( 127 + "{} on {}", 128 + attribute.name, node, 129 + ))) 130 + .with_context(|| { 131 + ( 132 + prev_debug_info.unwrap().into(), 133 + self.debug_info.clone().into(), 134 + ) 135 + .into() 136 + }); 137 + }; 134 138 } 135 139 Ok(()) 136 140 } ··· 180 184 Ok(edge) => edge, 181 185 Err(_) => { 182 186 return Err(ExecutionError::DuplicateEdge(format!( 183 - "({} -> {}) at {} and {}", 184 - source, 185 - sink, 186 - prev_debug_info.unwrap(), 187 - self.debug_info, 188 - )))? 187 + "({} -> {})", 188 + source, sink, 189 + ))) 190 + .with_context(|| { 191 + ( 192 + prev_debug_info.unwrap().into(), 193 + self.debug_info.clone().into(), 194 + ) 195 + .into() 196 + }); 189 197 } 190 198 }; 191 199 edge.attributes = self.attributes.clone(); ··· 243 251 GraphElementKey::EdgeAttribute(source, sink, attribute.name.clone()), 244 252 self.debug_info.clone(), 245 253 ); 246 - edge.attributes 247 - .add(attribute.name.clone(), value) 248 - .map_err(|_| { 249 - ExecutionError::DuplicateAttribute(format!( 250 - "{} on edge ({} -> {}) at {} and {}", 251 - attribute.name, 252 - source, 253 - sink, 254 - prev_debug_info.unwrap(), 255 - self.debug_info, 256 - )) 257 - })?; 254 + if let Err(_) = edge.attributes.add(attribute.name.clone(), value) { 255 + return Err(ExecutionError::DuplicateAttribute(format!( 256 + "{} on edge ({} -> {})", 257 + attribute.name, source, sink, 258 + ))) 259 + .with_context(|| { 260 + ( 261 + prev_debug_info.unwrap().into(), 262 + self.debug_info.clone().into(), 263 + ) 264 + .into() 265 + }); 266 + } 258 267 } 259 268 Ok(()) 260 269 }