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