From 56615f3ad9005878653b430d23bd76675dbd7ce5 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Thu, 16 May 2024 16:57:22 -0400 Subject: [PATCH 1/5] Add try catch in OnClicked() event handler --- .../Search/NodeSearchElementViewModel.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs index 1222d2bbd9c..05594c5a71c 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs @@ -362,8 +362,19 @@ protected virtual void OnClicked() { if (Clicked != null) { - var nodeModel = Model.CreateNode(); - Clicked(nodeModel, Position); + // Try to create the node based on the search element (in-Canvas search or library) + // The node creation can fail if the node constructor dependencies are not found or other reasons. + // This is a best effort to create the node and log the error both in console and toast notification if it fails. + try + { + var nodeModel = Model.CreateNode(); + Clicked(nodeModel, Position); + } + catch (Exception) + { + searchViewModel.dynamoViewModel.Model.Logger.Log("Failed to create node from search element: " + Model.Name); + searchViewModel.dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow("Failed to create node: " + Model.Name, true); + } } } From 5f4eef080ce32ca25f4223ed92625824d5fcc7f2 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Thu, 16 May 2024 17:10:52 -0400 Subject: [PATCH 2/5] update --- .../ViewModels/Search/NodeSearchElementViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs index 05594c5a71c..2949fc8b30e 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs @@ -362,7 +362,7 @@ protected virtual void OnClicked() { if (Clicked != null) { - // Try to create the node based on the search element (in-Canvas search or library) + // Try to create the node based on the search element from in-Canvas search // The node creation can fail if the node constructor dependencies are not found or other reasons. // This is a best effort to create the node and log the error both in console and toast notification if it fails. try From b1924811b564deef3d42352cb2acecf70fabd07b Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Thu, 16 May 2024 17:20:24 -0400 Subject: [PATCH 3/5] Update --- src/DynamoCoreWpf/Properties/Resources.Designer.cs | 9 +++++++++ src/DynamoCoreWpf/Properties/Resources.en-US.resx | 7 +++++-- src/DynamoCoreWpf/Properties/Resources.resx | 7 +++++-- .../ViewModels/Search/NodeSearchElementViewModel.cs | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 678040e808e..fea4f5cea3c 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -5026,6 +5026,15 @@ public static string NodeHelpWindowNodeType { } } + /// + /// Looks up a localized string similar to Failed to create node: . + /// + public static string NodeInCanvasSearchCreationError { + get { + return ResourceManager.GetString("NodeInCanvasSearchCreationError", resourceCulture); + } + } + /// /// Looks up a localized string similar to Dismisses the info messages on this node. Utilize when you want to design in graph failures, or the info message will not be relevant during graph execution.. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 249a2a95c4b..1d3c271eb00 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -582,7 +582,7 @@ Don't worry, you'll have the option to save your work. _Select All Edit menu | Select all nodes - + _Unpin All Preview Bubbles Edit menu | Unpin preview bubbles @@ -3983,4 +3983,7 @@ To make this file into a new template, save it to a different folder, then move #Learn more=https://primer2.dynamobim.org/1_developer_primer_intro/3_developing_for_dynamo/updating-your-packages-and-dynamo-libraries-for-dynamo-3x-net8 - + + Failed to create node: + + \ No newline at end of file diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index dbf2af5204f..1938f65dbc9 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -330,7 +330,7 @@ _Select All Edit menu | Select all nodes - + _Unpin All Preview Bubbles Edit menu | Unpin preview bubbles @@ -3970,4 +3970,7 @@ To make this file into a new template, save it to a different folder, then move #Learn more=https://primer2.dynamobim.org/1_developer_primer_intro/3_developing_for_dynamo/updating-your-packages-and-dynamo-libraries-for-dynamo-3x-net8 - + + Failed to create node: + + \ No newline at end of file diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs index 2949fc8b30e..02530cd611c 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs @@ -373,7 +373,7 @@ protected virtual void OnClicked() catch (Exception) { searchViewModel.dynamoViewModel.Model.Logger.Log("Failed to create node from search element: " + Model.Name); - searchViewModel.dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow("Failed to create node: " + Model.Name, true); + searchViewModel.dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow(Wpf.Properties.Resources.NodeInCanvasSearchCreationError + Model.Name, true); } } } From aef43f950b25020c956cc2fe9ea1a35d091b17f8 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Fri, 17 May 2024 09:22:50 -0400 Subject: [PATCH 4/5] update --- src/DynamoCoreWpf/PublicAPI.Unshipped.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt index 6ae526a235b..6ff50196f54 100644 --- a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt +++ b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt @@ -4878,6 +4878,7 @@ static Dynamo.Wpf.Properties.Resources.NodeHelpWindowNodeDescription.get -> stri static Dynamo.Wpf.Properties.Resources.NodeHelpWindowNodeInput.get -> string static Dynamo.Wpf.Properties.Resources.NodeHelpWindowNodeOutput.get -> string static Dynamo.Wpf.Properties.Resources.NodeHelpWindowNodeType.get -> string +static Dynamo.Wpf.Properties.Resources.NodeInCanvasSearchCreationError.get -> string static Dynamo.Wpf.Properties.Resources.NodeInfoDismissButtonToolTip.get -> string static Dynamo.Wpf.Properties.Resources.NodeInformationalStateDismiss.get -> string static Dynamo.Wpf.Properties.Resources.NodeInformationalStateDismissAll.get -> string From 3a333e7152d3e9309a7b2d8168ec110f4a745376 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Fri, 17 May 2024 10:20:18 -0400 Subject: [PATCH 5/5] Update --- .../ViewModels/Search/NodeSearchElementViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs index 02530cd611c..0ecaaec4f04 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs @@ -370,9 +370,9 @@ protected virtual void OnClicked() var nodeModel = Model.CreateNode(); Clicked(nodeModel, Position); } - catch (Exception) + catch (Exception ex) { - searchViewModel.dynamoViewModel.Model.Logger.Log("Failed to create node from search element: " + Model.Name); + searchViewModel.dynamoViewModel.Model.Logger.Log("Failed to create node from search element: " + Model.Name + "\n" + ex.Message); searchViewModel.dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow(Wpf.Properties.Resources.NodeInCanvasSearchCreationError + Model.Name, true); } }