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 GraphElementKey::NodeAttribute(node, attribute.name.clone()), 120 self.debug_info.clone(), 121 ); 122 - exec.graph[node] 123 .attributes 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 - })?; 134 } 135 Ok(()) 136 } ··· 180 Ok(edge) => edge, 181 Err(_) => { 182 return Err(ExecutionError::DuplicateEdge(format!( 183 - "({} -> {}) at {} and {}", 184 - source, 185 - sink, 186 - prev_debug_info.unwrap(), 187 - self.debug_info, 188 - )))? 189 } 190 }; 191 edge.attributes = self.attributes.clone(); ··· 243 GraphElementKey::EdgeAttribute(source, sink, attribute.name.clone()), 244 self.debug_info.clone(), 245 ); 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 - })?; 258 } 259 Ok(()) 260 }
··· 119 GraphElementKey::NodeAttribute(node, attribute.name.clone()), 120 self.debug_info.clone(), 121 ); 122 + if let Err(_) = exec.graph[node] 123 .attributes 124 .add(attribute.name.clone(), value) 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 + }; 138 } 139 Ok(()) 140 } ··· 184 Ok(edge) => edge, 185 Err(_) => { 186 return Err(ExecutionError::DuplicateEdge(format!( 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 + }); 197 } 198 }; 199 edge.attributes = self.attributes.clone(); ··· 251 GraphElementKey::EdgeAttribute(source, sink, attribute.name.clone()), 252 self.debug_info.clone(), 253 ); 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 + } 267 } 268 Ok(()) 269 }