Skip to content

Commit

Permalink
Remove StorageException class
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanyee33 committed Apr 14, 2024
1 parent 0837e5c commit 65573e6
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public DataLoadingException(Exception cause) {
super(cause);
}

public DataLoadingException(String message, Throwable cause) {
super(message, cause);
}

Check warning on line 18 in src/main/java/seedu/address/commons/exceptions/DataLoadingException.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/commons/exceptions/DataLoadingException.java#L17-L18

Added lines #L17 - L18 were not covered by tests

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.exceptions.CommandHistoryException;
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.util.exceptions.ParseException;
import seedu.address.model.person.Person;
import seedu.address.storage.exceptions.StorageException;

/**
* API of the Logic component
Expand All @@ -22,7 +22,7 @@ public interface Logic {
* @throws CommandException If an error occurs during command execution.
* @throws ParseException If an error occurs during parsing.
*/
String execute(String commandText) throws CommandException, ParseException, StorageException;
String execute(String commandText) throws CommandException, ParseException, DataLoadingException;

/**
* Gets the previous command's text.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.exceptions.CommandHistoryException;
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.util.AddressBookParser;
import seedu.address.logic.util.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;
import seedu.address.storage.exceptions.StorageException;

/**
* The main LogicManager of the app.
Expand All @@ -37,7 +37,7 @@ public LogicManager(Model model, Storage storage) {
}

@Override
public String execute(String commandText) throws CommandException, ParseException, StorageException {
public String execute(String commandText) throws CommandException, ParseException, DataLoadingException {
logger.info("----------------[USER COMMAND][" + commandText + "]");

Command command = AddressBookParser.parseCommand(commandText);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/seedu/address/storage/AddressBookStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.storage.exceptions.StorageException;

/**
* Represents a storage for {@link seedu.address.model.AddressBook}.
Expand Down Expand Up @@ -33,13 +32,13 @@ public interface AddressBookStorage {
/**
* Saves the given {@link ReadOnlyAddressBook} to the storage.
* @param addressBook cannot be null.
* @throws StorageException if there was any problem writing to the file.
* @throws DataLoadingException if there was any problem writing to the file.
*/
void saveAddressBook(ReadOnlyAddressBook addressBook) throws StorageException;
void saveAddressBook(ReadOnlyAddressBook addressBook) throws DataLoadingException;

/**
* @see #saveAddressBook(ReadOnlyAddressBook)
*/
void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws StorageException;
void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws DataLoadingException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import seedu.address.commons.util.JsonUtil;
import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.storage.exceptions.StorageException;

/**
* A class to access AddressBook data stored as a json file on the hard disk.
Expand Down Expand Up @@ -58,7 +57,7 @@ public Optional<ReadOnlyAddressBook> readAddressBook(Path filePath) throws DataL
}

@Override
public void saveAddressBook(ReadOnlyAddressBook addressBook) throws StorageException {
public void saveAddressBook(ReadOnlyAddressBook addressBook) throws DataLoadingException {
saveAddressBook(addressBook, filePath);
}

Expand All @@ -67,17 +66,17 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook) throws StorageExcep
*
* @param filePath location of the data. Cannot be null.
*/
public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws StorageException {
public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws DataLoadingException {
requireNonNull(addressBook);
requireNonNull(filePath);

try {
FileUtil.createIfMissing(filePath);
JsonUtil.saveJsonFile(addressBook, filePath);
} catch (AccessDeniedException e) {
throw new StorageException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);
throw new DataLoadingException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);

Check warning on line 77 in src/main/java/seedu/address/storage/JsonAddressBookStorage.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/storage/JsonAddressBookStorage.java#L77

Added line #L77 was not covered by tests
} catch (IOException ioe) {
throw new StorageException(String.format(FILE_OPS_ERROR_FORMAT, ioe.getMessage()), ioe);
throw new DataLoadingException(String.format(FILE_OPS_ERROR_FORMAT, ioe.getMessage()), ioe);

Check warning on line 79 in src/main/java/seedu/address/storage/JsonAddressBookStorage.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/storage/JsonAddressBookStorage.java#L79

Added line #L79 was not covered by tests
}

}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.storage.exceptions.StorageException;

/**
* API of the Storage component
Expand All @@ -28,7 +27,7 @@ public interface Storage extends AddressBookStorage, UserPrefsStorage {
Optional<ReadOnlyAddressBook> readAddressBook() throws DataLoadingException;

@Override
void saveAddressBook(ReadOnlyAddressBook addressBook) throws StorageException;
void saveAddressBook(ReadOnlyAddressBook addressBook) throws DataLoadingException;

ReadOnlyAddressBook readInitialAddressBook() throws DataLoadingException;

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.exceptions.StorageException;

/**
* Manages storage of AddressBook data in local storage.
Expand Down Expand Up @@ -67,12 +66,12 @@ public Optional<ReadOnlyAddressBook> readAddressBook(Path filePath) throws DataL
}

@Override
public void saveAddressBook(ReadOnlyAddressBook addressBook) throws StorageException {
public void saveAddressBook(ReadOnlyAddressBook addressBook) throws DataLoadingException {
saveAddressBook(addressBook, addressBookStorage.getAddressBookFilePath());
}

@Override
public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws StorageException {
public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws DataLoadingException {
logger.fine("Attempting to write to data file: " + filePath);
addressBookStorage.saveAddressBook(addressBook, filePath);
}
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.exceptions.CommandHistoryException;
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.util.exceptions.ParseException;
import seedu.address.storage.exceptions.StorageException;

/**
* The UI component that is responsible for receiving user command inputs.
Expand Down Expand Up @@ -56,7 +56,7 @@ private void handleCommandEntered() {
try {
commandExecutor.execute(commandText);
commandTextField.setText("");
} catch (CommandException | ParseException | StorageException e) {
} catch (CommandException | ParseException | DataLoadingException e) {

Check warning on line 59 in src/main/java/seedu/address/ui/CommandBox.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CommandBox.java#L59

Added line #L59 was not covered by tests
setStyleToIndicateCommandFailure();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/ui/CommandExecutor.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package seedu.address.ui;

import seedu.address.commons.exceptions.CommandHistoryException;
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.util.exceptions.ParseException;
import seedu.address.storage.exceptions.StorageException;

/**
* Represents an API which supports command execution and history tracking.
Expand All @@ -15,7 +15,7 @@ public interface CommandExecutor {
*
* @see seedu.address.logic.Logic#execute(String)
*/
String execute(String commandText) throws CommandException, ParseException, StorageException;
String execute(String commandText) throws CommandException, ParseException, DataLoadingException;

/**
* Gets the previous command's text.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.exceptions.CommandHistoryException;
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.logic.Logic;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.util.exceptions.ParseException;
import seedu.address.storage.exceptions.StorageException;

/**
* The Main Window. Provides the basic application layout containing
Expand Down Expand Up @@ -195,13 +195,13 @@ public void showMessage(String msg) {
private class RecordedCommandExecutor implements CommandExecutor {

@Override
public String execute(String commandText) throws CommandException, ParseException, StorageException {
public String execute(String commandText) throws CommandException, ParseException, DataLoadingException {
String commandResult;
try {
commandResult = logic.execute(commandText);
logger.info("Result: " + commandResult);
showMessage(commandResult);
} catch (CommandException | ParseException | StorageException e) {
} catch (CommandException | ParseException | DataLoadingException e) {

Check warning on line 204 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L204

Added line #L204 was not covered by tests
logger.info("An error occurred while executing command: " + commandText);
showMessage(e.getMessage());
throw e;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.util.exceptions.ParseException;
Expand All @@ -20,7 +21,6 @@
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.exceptions.StorageException;

public class LogicManagerTest {
@TempDir
Expand Down Expand Up @@ -69,7 +69,7 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException
* @see #assertCommandFailure(String, Class, String, Model)
*/
private void assertCommandSuccess(String inputCommand, String expectedMessage,
Model expectedModel) throws CommandException, ParseException, StorageException {
Model expectedModel) throws CommandException, ParseException, DataLoadingException {
String result = logic.execute(inputCommand);
assertEquals(expectedMessage, result);
assertEquals(expectedModel, model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.storage.exceptions.StorageException;

public class JsonAddressBookStorageTest {
private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonAddressBookStorageTest");
Expand Down Expand Up @@ -98,7 +97,7 @@ private void saveAddressBook(ReadOnlyAddressBook addressBook, String filePath) {
try {
new JsonAddressBookStorage(Paths.get(filePath))
.saveAddressBook(addressBook, addToTestDataPathIfNotNull(filePath));
} catch (StorageException e) {
} catch (DataLoadingException e) {
throw new AssertionError("There should not be an error writing to the file.", e);
}
}
Expand Down

0 comments on commit 65573e6

Please sign in to comment.