Skip to content

Commit 0a07fd8

Browse files
committed
WIP: New error message
1 parent 966b481 commit 0a07fd8

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
22

33
use graph_craft::document::value::TaggedValue;
44
use graph_craft::document::{DocumentNodeImplementation, InlineRust, NodeInput};
5-
use graph_craft::proto::GraphErrors;
5+
use graph_craft::proto::{GraphError, GraphErrorType, GraphErrors};
66
use graph_craft::{Type, concrete};
77
use graphene_std::uuid::NodeId;
88
use interpreted_executor::dynamic_executor::{NodeTypes, ResolvedDocumentNodeTypesDelta};
@@ -129,7 +129,13 @@ impl NodeNetworkInterface {
129129
InputConnector::Export(_) => false,
130130
})
131131
}
132-
DocumentNodeImplementation::ProtoNode(_) => self.resolved_types.node_graph_errors.iter().any(|error| error.node_path == node_path),
132+
DocumentNodeImplementation::ProtoNode(_) => self.resolved_types.node_graph_errors.iter().any(|error| {
133+
error.node_path == node_path
134+
&& match error.error {
135+
GraphErrorType::InvalidImplementations { inputs, error_inputs } => error_inputs.iter().any(|solution| solution.iter().any(|(index, _)| index == *input_index)),
136+
_ => True,
137+
}
138+
}),
133139
DocumentNodeImplementation::Extract => false,
134140
}
135141
}

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

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ pub enum GraphErrorType {
542542
UnexpectedGenerics { index: usize, inputs: Vec<Type> },
543543
NoImplementations,
544544
NoConstructor,
545-
InvalidImplementations { inputs: String, error_inputs: Vec<Vec<(usize, (Type, Type))>> },
545+
// The first vec represents a list of correct NodeIOTypes
546+
// The second vec represents what the input index and what it expects
547+
InvalidImplementations { inputs: String, error_inputs: Vec<Vec<(usize, Type)>> },
546548
MultipleImplementations { inputs: String, valid: Vec<NodeIOTypes> },
547549
}
548550
impl Debug for GraphErrorType {
@@ -554,31 +556,26 @@ impl Debug for GraphErrorType {
554556
GraphErrorType::NoImplementations => write!(f, "No implementations found"),
555557
GraphErrorType::NoConstructor => write!(f, "No construct found for node"),
556558
GraphErrorType::InvalidImplementations { inputs, error_inputs } => {
557-
let format_error = |(index, (found, expected)): &(usize, (Type, Type))| {
558-
let index = index + 1;
559-
format!(
560-
"\
561-
• Input {index}:\n\
562-
…found: {found}\n\
563-
…expected: {expected}\
564-
"
565-
)
566-
};
567-
let format_error_list = |errors: &Vec<(usize, (Type, Type))>| errors.iter().map(format_error).collect::<Vec<_>>().join("\n");
568-
let mut errors = error_inputs.iter().map(format_error_list).collect::<Vec<_>>();
569-
errors.sort();
570-
let errors = errors.join("\n");
571-
let incompatibility = if errors.chars().filter(|&c| c == '•').count() == 1 {
572-
"This input type is incompatible:"
573-
} else {
574-
"These input types are incompatible:"
575-
};
559+
let mut solutions = error_inputs
560+
.iter()
561+
.enumerate()
562+
.map(|(solution_index, expected_inputs)| {
563+
format!(
564+
"• Solution {}{}",
565+
solution_index + 1,
566+
expected_inputs
567+
.map(|(index, expected_type)| format!("Input {} expected: {}\n", index + 1, expected_type))
568+
.collect::<String>()
569+
)
570+
})
571+
.collect::<Vec<_>>()
572+
.join("\n");
576573

577574
write!(
578575
f,
579576
"\
580-
{incompatibility}\n\
581-
{errors}\n\
577+
Invalid input solutions:\n\
578+
{solutions}\n\
582579
\n\
583580
The node is currently receiving all of the following input types:\n\
584581
{inputs}\n\
@@ -766,10 +763,7 @@ impl TypingContext {
766763
.zip([&node_io.call_argument].into_iter().chain(&node_io.inputs).cloned())
767764
.enumerate()
768765
.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-
})
766+
.map(|(index, (_, expected))| (index, expected))
773767
.collect::<Vec<_>>();
774768
if current_errors.len() < best_errors {
775769
best_errors = current_errors.len();

node-graph/libraries/core-types/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl std::fmt::Debug for Type {
369369
Self::Concrete(ty) => format!("Concrete<{}, {:?}>", ty.name, ty.id),
370370
#[cfg(not(feature = "type_id_logging"))]
371371
Self::Concrete(ty) => format_type(&ty.name),
372-
Self::Fn(call_arg, return_value) => format!("{return_value:?} called with {call_arg:?}"),
372+
Self::Fn(call_arg, return_value) => format!("{return_value:?}"),
373373
Self::Future(ty) => format!("{ty:?}"),
374374
};
375375
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
@@ -382,7 +382,7 @@ impl std::fmt::Display for Type {
382382
let result = match self {
383383
Type::Generic(name) => name.to_string(),
384384
Type::Concrete(ty) => format_type(&ty.name),
385-
Type::Fn(call_arg, return_value) => format!("{return_value} called with {call_arg}"),
385+
Type::Fn(call_arg, return_value) => format!("{return_value}"),
386386
Type::Future(ty) => ty.to_string(),
387387
};
388388
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");

0 commit comments

Comments
 (0)