Skip to content

Commit

Permalink
fix bug for todo
Browse files Browse the repository at this point in the history
  • Loading branch information
chiralcentre committed Feb 27, 2024
1 parent ede4c8c commit 7237a29
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions data/taskList.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
D | | ip | 2024-02-23 2359
E | | sports | 2024-02-23 1700 | 2024-02-23 1800
D | X | ip | 2024-02-23 2359
E | X | dinner | 2024-02-23 1700 | 2024-02-23 1800
T | X | hello
1 change: 0 additions & 1 deletion src/main/java/felix/Felix.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void main(String[] args) throws IOException, FelixException {

public String getResponse(String input) {
try {
tasks = storage.getTasksFromFile();
Command command = parser.getCommand(input);
return command.execute(tasks, ui, storage);
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/felix/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean hasKeyword(String keyword) {
*
* @return task represented by file line.
*/
public static Task createTaskFromFileLine(String line) {
public static Task createTaskFromFileLine(String line) throws IndexOutOfBoundsException {
String[] words = line.split(" \\| ");
Task task;
if (words[0].equals("T")) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/felix/utils/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ private Task generateTask(String[] words) throws FelixException {
Task task;
if (words[0].equals("todo")) {
try {
if (words[1].isEmpty()) {
throw new FelixException("The description of a todo cannot be empty");
}
task = new ToDo(words[1]);
} catch (IndexOutOfBoundsException e) {
throw new FelixException("The description of a todo cannot be empty");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/felix/utils/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public TaskList getTasksFromFile() throws FelixException {
throw new FelixException("Cannot read from file");
} catch (DateTimeParseException err) {
throw new FelixException("datetime not in the format \"yyyy-MM-dd HHmm\"");
} catch (IndexOutOfBoundsException err) {
throw new FelixException("file line is in wrong format");
}
}

Expand Down

0 comments on commit 7237a29

Please sign in to comment.