Skip to content

Commit

Permalink
Save data in every action
Browse files Browse the repository at this point in the history
  • Loading branch information
A1WAYSD committed Sep 20, 2023
1 parent 1461bb9 commit 6bf7ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
TODO | 1 | watch movies
DEADLINE | 0 | submit user guide | 2024-12-31
TODO | 1 | test
14 changes: 10 additions & 4 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
public class Duke {
private static final String SAVING_ERROR_MSG = "⚠ Oops! Something wrong when closing:(";
private static final String BYE_MSG = "Bye!\n\"Beware the barrenness of a busy life.\"";
private Parser parser;
private Storage storage;
private TaskList tasks;
private Stage stage;
private final Parser parser;
private final Storage storage;
private final TaskList tasks;
private final Stage stage;

/**
* Initializes the chat robot. Establishes task list and parser.
Expand All @@ -40,12 +40,15 @@ public Duke(Stage stage) {
public String getResponse(String input) {
try {
String output = parser.parse(input);
this.storage.save(this.tasks);
if (!parser.isRunning()) {
return exit();
}
return output;
} catch (DukeException e) {
return handleException(e);
} catch (IOException e) {
return handleException(new DukeException("saving error"));
}
}

Expand Down Expand Up @@ -81,6 +84,9 @@ private String handleException(DukeException e) {
case "undefined":
warning = "⚠ Sorry! I am not able to understand you. Try another language:D";
break;
case "saving error":
warning = SAVING_ERROR_MSG;
break;
default:
warning = "⚠ Oops! Something went wrong:(";
break;
Expand Down

0 comments on commit 6bf7ea2

Please sign in to comment.