Skip to content

Commit 77f8bfd

Browse files
committed
Improve clarify of type errors and tooltip diagnostics
1 parent 6e7f218 commit 77f8bfd

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ impl NodeGraphMessageHandler {
22342234
let mut inputs = inputs.into_iter().map(|input| {
22352235
input.map(|input| FrontendGraphInput {
22362236
data_type: FrontendGraphDataType::displayed_type(&input.ty, &input.type_source),
2237-
resolved_type: Some(format!("{:?} from {:?}", &input.ty, input.type_source)),
2237+
resolved_type: Some(format!("{:?}", &input.ty)),
22382238
valid_types: input.valid_types.iter().map(|ty| ty.to_string()).collect(),
22392239
name: input.input_name.unwrap_or_else(|| input.ty.nested_type().to_string()),
22402240
description: input.input_description.unwrap_or_default(),
@@ -2258,7 +2258,7 @@ impl NodeGraphMessageHandler {
22582258
data_type: frontend_data_type,
22592259
name: "Output 1".to_string(),
22602260
description: String::new(),
2261-
resolved_type: primary_output_type.map(|(input, type_source)| format!("{input:?} from {type_source:?}")),
2261+
resolved_type: primary_output_type.map(|(input, _)| format!("{input:?}")),
22622262
connected_to,
22632263
})
22642264
} else {
@@ -2292,7 +2292,7 @@ impl NodeGraphMessageHandler {
22922292
data_type: frontend_data_type,
22932293
name: output_name,
22942294
description: String::new(),
2295-
resolved_type: exposed_output.clone().map(|(input, type_source)| format!("{input:?} from {type_source:?}")),
2295+
resolved_type: exposed_output.clone().map(|(input, _)| format!("{input:?}")),
22962296
connected_to,
22972297
});
22982298
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl NodeNetworkInterface {
816816
data_type,
817817
name: import_name,
818818
description: String::new(),
819-
resolved_type: Some(format!("{input_type:?} from {type_source:?}")),
819+
resolved_type: Some(format!("{input_type:?}")),
820820
connected_to,
821821
},
822822
click_target,
@@ -901,7 +901,7 @@ impl NodeNetworkInterface {
901901
data_type: frontend_data_type,
902902
name: export_name,
903903
description: String::new(),
904-
resolved_type: input_type.map(|(export_type, source)| format!("{export_type:?} from {source:?}")),
904+
resolved_type: input_type.map(|(export_type, _source)| format!("{export_type:?}")),
905905
valid_types: self.valid_input_types(&InputConnector::Export(*export_index), network_path).iter().map(|ty| ty.to_string()).collect(),
906906
connected_to,
907907
},

frontend/src/components/views/Graph.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,12 @@
581581
}
582582
583583
function dataTypeTooltip(value: FrontendGraphInput | FrontendGraphOutput): string {
584-
return value.resolvedType ? `Resolved Data:\n${value.resolvedType}` : `Unresolved Data ${value.dataType}`;
584+
return value.resolvedType ? `Data Type:\n${value.resolvedType}` : `Data Type (Unresolved):\n${value.dataType}`;
585585
}
586586
587587
function validTypesText(value: FrontendGraphInput): string {
588-
return `Valid Types:\n${value.validTypes.join(",\n ")}`;
588+
const validTypes = value.validTypes.length > 0 ? value.validTypes.map((x) => `• ${x}`).join("\n") : "None";
589+
return `Valid Types:\n${validTypes}`;
589590
}
590591
591592
function outputConnectedToText(output: FrontendGraphOutput): string {

node-graph/gcore/src/types.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,26 +324,30 @@ fn format_type(ty: &str) -> String {
324324

325325
impl core::fmt::Debug for Type {
326326
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
327-
match self {
328-
Self::Generic(arg0) => write!(f, "Generic<{arg0}>"),
327+
let result = match self {
328+
Self::Generic(name) => name.to_string(),
329329
#[cfg(feature = "type_id_logging")]
330-
Self::Concrete(arg0) => write!(f, "Concrete<{}, {:?}>", arg0.name, arg0.id),
330+
Self::Concrete(ty) => format!("Concrete<{}, {:?}>", ty.name, ty.id),
331331
#[cfg(not(feature = "type_id_logging"))]
332-
Self::Concrete(arg0) => write!(f, "Concrete<{}>", format_type(&arg0.name)),
333-
Self::Fn(arg0, arg1) => write!(f, "{arg0:?} → {arg1:?}"),
334-
Self::Future(arg0) => write!(f, "Future<{arg0:?}>"),
335-
}
332+
Self::Concrete(ty) => format_type(&ty.name),
333+
Self::Fn(call_arg, return_value) => format!("{return_value:?} called with {call_arg:?}"),
334+
Self::Future(ty) => format!("{ty:?}"),
335+
};
336+
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
337+
write!(f, "{}", result)
336338
}
337339
}
338340

339341
impl std::fmt::Display for Type {
340342
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
341-
match self {
342-
Type::Generic(name) => write!(f, "{name}"),
343-
Type::Concrete(ty) => write!(f, "{}", format_type(&ty.name)),
344-
Type::Fn(input, output) => write!(f, "{input} → {output}"),
345-
Type::Future(ty) => write!(f, "Future<{ty}>"),
346-
}
343+
let result = match self {
344+
Type::Generic(name) => name.to_string(),
345+
Type::Concrete(ty) => format_type(&ty.name),
346+
Type::Fn(call_arg, return_value) => format!("{return_value} called with {call_arg}"),
347+
Type::Future(ty) => ty.to_string(),
348+
};
349+
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
350+
write!(f, "{}", result)
347351
}
348352
}
349353

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,19 +552,36 @@ impl core::fmt::Debug for GraphErrorType {
552552
GraphErrorType::NoImplementations => write!(f, "No implementations found"),
553553
GraphErrorType::NoConstructor => write!(f, "No construct found for node"),
554554
GraphErrorType::InvalidImplementations { inputs, error_inputs } => {
555-
let format_error = |(index, (_found, expected)): &(usize, (Type, Type))| format!("• Input {}: {expected}, found: {_found}", index + 1);
556-
let format_error_list = |errors: &Vec<(usize, (Type, Type))>| errors.iter().map(format_error).collect::<Vec<_>>().join("\n").replace("Option<Arc<OwnedContextImpl>>", "Context");
555+
let format_error = |(index, (found, expected)): &(usize, (Type, Type))| {
556+
let index = index + 1;
557+
format!(
558+
"\
559+
• Input {index}:\n\
560+
…found: {found}\n\
561+
…expected: {expected}\
562+
"
563+
)
564+
};
565+
let format_error_list = |errors: &Vec<(usize, (Type, Type))>| errors.iter().map(format_error).collect::<Vec<_>>().join("\n");
557566
let mut errors = error_inputs.iter().map(format_error_list).collect::<Vec<_>>();
558567
errors.sort();
559-
let inputs = inputs.replace("Option<Arc<OwnedContextImpl>>", "Context");
568+
let errors = errors.join("\n");
569+
let incompatibility = if errors.chars().filter(|&c| c == '•').count() == 1 {
570+
"This input type is incompatible:"
571+
} else {
572+
"These input types are incompatible:"
573+
};
574+
560575
write!(
561576
f,
562-
"This node isn't compatible with the combination of types for the data it is given:\n\
563-
{inputs}\n\
577+
"\
578+
{incompatibility}\n\
579+
{errors}\n\
564580
\n\
565-
Each invalid input should be replaced by data with one of these supported types:\n\
566-
{}",
567-
errors.join("\n")
581+
The node is currently receiving all of the following input types:\n\
582+
{inputs}\n\
583+
This is not a supported arrangement of types for the node.\
584+
"
568585
)
569586
}
570587
GraphErrorType::MultipleImplementations { inputs, valid } => write!(f, "Multiple implementations found ({inputs}):\n{valid:#?}"),

0 commit comments

Comments
 (0)