AY2425S1-CS2103T-T12-4 / tp

MIT License
0 stars 5 forks source link

Flush CommandLog after load commands #327

Closed JJtan2002 closed 3 days ago

JJtan2002 commented 3 days ago

This PR fixes a bug identified in issue #287 by the commandLog after each load command to prevent unexpected behaviors with undo.

The undo command was implemented using a commandLog, which is a Stack storing all commands previously executed.

The undo after load bug arises because while we load a different addressBook state, the commandLog persists and allows users to undo commands that do not apply to the loaded addressBook. For example, try this sequence of commands in our 1.5.1 release:

  1. Run a clear command to obtain an empty addressBook
  2. Run a save command on this empty addressBook
  3. Run an add command, like add n/test
  4. Run load command to return to the empty addressBook
  5. Run undo and see an exception in the terminal

In this case, GamerBook is trying to undo the add command on the loaded empty state! The user will be exposed to an exception because we are trying to delete a non-existant person. This is just one of many possible unexpected behaviors arising from this functionality bug.

This PR does not violate the feature freeze by Q3, as we are fixing a bug to ensure that undo after load follows reasonably correct behavior.

ChenLeiyu commented 3 days ago

LGTM :) merged.