Skip to content

Commit

Permalink
[DYN-7942] Catch exception during undo operation. (#15812)
Browse files Browse the repository at this point in the history
  • Loading branch information
reddyashish authored Feb 6, 2025
1 parent 20d268a commit 5f77cfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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);
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

0 comments on commit 5f77cfc

Please sign in to comment.