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

Add more context on which part of the statement returned an error

Changed files
+26 -6
src
execution
+20 -5
src/execution/lazy/statements.rs
··· 112 112 } 113 113 114 114 pub(super) fn evaluate(&self, exec: &mut EvaluationContext) -> Result<(), ExecutionError> { 115 - let node = self.node.evaluate_as_graph_node(exec)?; 115 + let node = self 116 + .node 117 + .evaluate_as_graph_node(exec) 118 + .with_context(|| "Evaluating target node".to_string().into())?; 116 119 for attribute in &self.attributes { 117 120 let value = attribute.value.evaluate(exec)?; 118 121 let prev_debug_info = exec.prev_element_debug_info.insert( ··· 175 178 } 176 179 177 180 pub(super) fn evaluate(&self, exec: &mut EvaluationContext) -> Result<(), ExecutionError> { 178 - let source = self.source.evaluate_as_graph_node(exec)?; 179 - let sink = self.sink.evaluate_as_graph_node(exec)?; 181 + let source = self 182 + .source 183 + .evaluate_as_graph_node(exec) 184 + .with_context(|| "Evaluating edge source".to_string().into())?; 185 + let sink = self 186 + .sink 187 + .evaluate_as_graph_node(exec) 188 + .with_context(|| "Evaluating edge sink".to_string().into())?; 180 189 let prev_debug_info = exec 181 190 .prev_element_debug_info 182 191 .insert(GraphElementKey::Edge(source, sink), self.debug_info.clone()); ··· 236 245 } 237 246 238 247 pub(super) fn evaluate(&self, exec: &mut EvaluationContext) -> Result<(), ExecutionError> { 239 - let source = self.source.evaluate_as_graph_node(exec)?; 240 - let sink = self.sink.evaluate_as_graph_node(exec)?; 248 + let source = self 249 + .source 250 + .evaluate_as_graph_node(exec) 251 + .with_context(|| "Evaluating edge source".to_string().into())?; 252 + let sink = self 253 + .sink 254 + .evaluate_as_graph_node(exec) 255 + .with_context(|| "Evaluating edge sink".to_string().into())?; 241 256 for attribute in &self.attributes { 242 257 let value = attribute.value.evaluate(exec)?; 243 258 let edge = match exec.graph[source].get_edge_mut(sink) {
+6 -1
src/execution/lazy/values.rs
··· 13 13 use std::fmt; 14 14 15 15 use crate::execution::error::ExecutionError; 16 + use crate::execution::error::ResultWithExecutionError; 16 17 use crate::graph::GraphNodeRef; 17 18 use crate::graph::SyntaxNodeRef; 18 19 use crate::graph::Value; ··· 184 185 } 185 186 186 187 fn resolve<'a>(&self, exec: &'a mut EvaluationContext) -> Result<LazyValue, ExecutionError> { 187 - let scope = self.scope.as_ref().evaluate_as_syntax_node(exec)?; 188 + let scope = self 189 + .scope 190 + .as_ref() 191 + .evaluate_as_syntax_node(exec) 192 + .with_context(|| format!("Evaluating scope of variable _.{}", self.name).into())?; 188 193 let scoped_store = &exec.scoped_store; 189 194 scoped_store.evaluate(&scope, &self.name, exec) 190 195 }