Skip to content

Commit 6e505de

Browse files
committed
Correct error offset for convert node
1 parent 118c587 commit 6e505de

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

node-graph/graph-craft/src/document.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub struct OriginalLocation {
8484
pub dependants: Vec<Vec<NodeId>>,
8585
/// A list of flags indicating whether the input is exposed in the UI
8686
pub inputs_exposed: Vec<bool>,
87+
// For automatically inserted convert and into nodes, if there is an error display it on the node it is connect to
88+
pub auto_convert_index: Option<usize>,
8789
}
8890

8991
impl Default for DocumentNode {
@@ -664,12 +666,9 @@ impl NodeNetwork {
664666
if node.original_location.path.is_some() {
665667
log::warn!("Attempting to overwrite node path");
666668
} else {
667-
node.original_location = OriginalLocation {
668-
path: Some(new_path),
669-
inputs_exposed: node.inputs.iter().map(|input| input.is_exposed()).collect(),
670-
dependants: (0..node.implementation.output_count()).map(|_| Vec::new()).collect(),
671-
..Default::default()
672-
};
669+
node.original_location.path = Some(new_path);
670+
node.original_location.inputs_exposed = node.inputs.iter().map(|input| input.is_exposed()).collect();
671+
node.original_location.dependants = (0..node.implementation.output_count()).map(|_| Vec::new()).collect();
673672
}
674673
}
675674
}

node-graph/graph-craft/src/proto.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ pub enum GraphErrorType {
542542
UnexpectedGenerics { index: usize, inputs: Vec<Type> },
543543
NoImplementations,
544544
NoConstructor,
545+
// The first vec represents a list of correct NodeIOTypes
546+
// The second vec represents what the input index and what it expects
545547
InvalidImplementations { inputs: String, error_inputs: Vec<Vec<(usize, (Type, Type))>> },
546548
MultipleImplementations { inputs: String, valid: Vec<NodeIOTypes> },
547549
}
@@ -756,20 +758,20 @@ impl TypingContext {
756758

757759
match valid_impls.as_slice() {
758760
[] => {
761+
log::debug!("{:?}", node.original_location);
762+
let convert_node_index_offset = node.original_location.auto_convert_index.unwrap_or(0);
759763
let mut best_errors = usize::MAX;
760764
let mut error_inputs = Vec::new();
761765
for node_io in impls.keys() {
766+
// For errors on convert nodes, add to the input index to it is correct for the node it is connected to
762767
let current_errors = [call_argument]
763768
.into_iter()
764769
.chain(&inputs)
765770
.cloned()
766771
.zip([&node_io.call_argument].into_iter().chain(&node_io.inputs).cloned())
767772
.enumerate()
768773
.filter(|(_, (p1, p2))| !valid_type(p1, p2))
769-
.map(|(index, ty)| {
770-
let i = node.original_location.inputs(index).min_by_key(|s| s.node.len()).map(|s| s.index).unwrap_or(index);
771-
(i, ty)
772-
})
774+
.map(|(index, expected)| (index - 1 + convert_node_index_offset, expected))
773775
.collect::<Vec<_>>();
774776
if current_errors.len() < best_errors {
775777
best_errors = current_errors.len();
@@ -783,7 +785,7 @@ impl TypingContext {
783785
.into_iter()
784786
.chain(&inputs)
785787
.enumerate()
786-
.filter_map(|(i, t)| if i == 0 { None } else { Some(format!("• Input {i}: {t}")) })
788+
.filter_map(|(i, t)| if i == 0 { None } else { Some(format!("• Input {}: {t}", i + convert_node_index_offset)) })
787789
.collect::<Vec<_>>()
788790
.join("\n");
789791
Err(vec![GraphError::new(node, GraphErrorType::InvalidImplementations { inputs, error_inputs })])

node-graph/preprocessor/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
8686
} else {
8787
identity_node.clone()
8888
};
89-
89+
let mut original_location = OriginalLocation::default();
90+
original_location.auto_convert_index = Some(i);
9091
DocumentNode {
9192
inputs,
9293
implementation: DocumentNodeImplementation::ProtoNode(proto_node),
9394
visible: true,
95+
original_location,
9496
..Default::default()
9597
}
9698
}

0 commit comments

Comments
 (0)