Skip to content

Commit

Permalink
Modify logs to show target file location
Browse files Browse the repository at this point in the history
When a file is missing or corrupted,
the log messages do not include the targetted filename.

To make the log messages clearer
without needing users to refer to past logs,
let's update the log message to
include the local path to target file.
  • Loading branch information
Eclipse-Dominator committed May 12, 2023
1 parent 6fc857a commit 4a680fb
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
logger.info("Creating a new data file " + storage.getAddressBookFilePath()
+ " populated with a sample AddressBook");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
logger.warning("Data file at " + storage.getAddressBookFilePath()
+ " might be corrupted or not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
logger.warning("Problem while reading from the file " + storage.getAddressBookFilePath()
+ ". Will be starting with an empty AddressBook");
initialData = new AddressBook();
}

Expand Down Expand Up @@ -118,12 +121,12 @@ protected Config initConfig(Path configFilePath) {
try {
Optional<Config> configOptional = ConfigUtil.readConfig(configFilePathUsed);
if (!configOptional.isPresent()) {
logger.info("Config file not found. Will be starting with a new default config file.");
logger.info("Creating new config file " + configFilePathUsed);
}
initializedConfig = configOptional.orElse(new Config());
} catch (DataConversionException e) {
logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. "
+ "Using default config properties");
logger.warning("Config file " + configFilePathUsed
+ " is not in the correct format. Using default config properties");
initializedConfig = new Config();
}

Expand All @@ -143,21 +146,23 @@ protected Config initConfig(Path configFilePath) {
*/
protected UserPrefs initPrefs(UserPrefsStorage storage) {
Path prefsFilePath = storage.getUserPrefsFilePath();
logger.info("Using prefs file : " + prefsFilePath);
logger.info("Using preference file : " + prefsFilePath);

UserPrefs initializedPrefs;
try {
Optional<UserPrefs> prefsOptional = storage.readUserPrefs();
if (!prefsOptional.isPresent()) {
logger.info("Prefs file not found. Will be starting with a new default prefs file.");
logger.info("Creating new preference file " + prefsFilePath);
}
initializedPrefs = prefsOptional.orElse(new UserPrefs());
} catch (DataConversionException e) {
logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct format. "
+ "Using default user prefs");
logger.warning(
"Preference file at " + prefsFilePath
+ " might be missing or corrupted. Using default preferences");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
logger.warning("Problem while reading from preference file " + prefsFilePath
+ ". Will be starting with an empty AddressBook");
initializedPrefs = new UserPrefs();
}

Expand Down

0 comments on commit 4a680fb

Please sign in to comment.