Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DYN-7942] Catch exception during undo operation. #15812

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/DynamoCore/Core/UndoRedoRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamo.Graph.Connectors;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;

namespace Dynamo.Core
{
Expand Down Expand Up @@ -56,7 +57,7 @@ internal interface IUndoRedoRecorderClient
ModelBase GetModelForElement(XmlElement modelData);
}

internal class UndoRedoRecorder
internal class UndoRedoRecorder : LogSourceBase
{
#region Private Class Data Members

Expand Down Expand Up @@ -241,7 +242,15 @@ public XmlElement PopFromUndoGroup()
"UndoStack cannot be popped with non-empty RedoStack");
}

return PopActionGroupFromUndoStack();
try
{
return PopActionGroupFromUndoStack();
}
catch (InvalidOperationException ex)
{
Log(ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logging to Dynamo Console?

Copy link
Contributor Author

@reddyashish reddyashish Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the log(exception) is logged as error to the log file.

return null;
}
}
#endregion

Expand Down Expand Up @@ -310,7 +319,7 @@ private void SetNodeAction(XmlNode childNode, string action)
childNode.Attributes.Append(actionAttribute);
}

private XmlElement PopActionGroupFromUndoStack()
internal XmlElement PopActionGroupFromUndoStack()
{
if (CanUndo == false)
{
Expand Down
4 changes: 2 additions & 2 deletions test/DynamoCoreTests/UndoRedoRecorderTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
Expand Down Expand Up @@ -565,7 +565,7 @@ public void TestClearingStacks01()
public void TestPopFromUndoGroup()
{
//Assert that it cannot pop from an empty undostack
Assert.Throws<InvalidOperationException>(() => { recorder.PopFromUndoGroup(); });
Assert.Throws<InvalidOperationException>(() => { recorder.PopActionGroupFromUndoStack(); });

//Add models
workspace.AddModel(new DummyModel(1, 10));
Expand Down
Loading