Skip to content

Commit

Permalink
Merge pull request #213 from kelvneo/logger-fix
Browse files Browse the repository at this point in the history
Change Logger error behaviour and separate StorageManager from Logger
  • Loading branch information
kelvneo authored Nov 7, 2021
2 parents c397551 + 17ab9fd commit f34071e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions src/main/java/terminus/Terminus.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Terminus {
* Enters the main entry-point for the terminus.Terminus application.
*/
public static void main(String[] args) {
new Terminus().run();
new Terminus().start();
}

Terminus() {
Expand All @@ -49,26 +49,31 @@ public static void main(String[] args) {
/**
* Starts the program.
*/
public void run() {
public void start() {
initialize();
runCommandsUntilExit();
exit();
}

/**
* Initializes all the file-related information for TermiNUS.
*/
void initialize() {
try {
TerminusLogger.initializeLogger();
TerminusLogger.info("Starting Terminus...");
this.workspace = "";
this.storageManager = new StorageManager(dataDirectory, MAIN_JSON);
this.moduleManager = this.storageManager.initialize();
} catch (IOException e) {
TerminusLogger.warning("Log file loading has failed.", e.fillInStackTrace());
ui.printSection(
String.format(Messages.ERROR_MESSAGE_FILE, e.getMessage()),
"TermiNUS may still run, but your changes may not be saved.",
"Check 'terminus.log' for more information."
"TermiNUS is unable to interact with the logging file.",
"Any logs generated in this session will not be saved."
);
}

TerminusLogger.info("Starting Terminus...");
try {
this.workspace = "";
this.storageManager = new StorageManager(dataDirectory, MAIN_JSON);
this.moduleManager = this.storageManager.initialize();
} catch (InvalidFileException e) {
TerminusLogger.warning("Data file loading has failed.", e.fillInStackTrace());
ui.printSection(e.getMessage(),
Expand All @@ -88,7 +93,7 @@ void initialize() {

TerminusLogger.info("Terminus has started.");
}

CommandResult handleUserInput(String input) {
try {
Command command = parser.parseCommand(input);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/terminus/TerminusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void run_invalidCommand_exit_success() {
InputStream in = new ByteArrayInputStream(input.getBytes());
Terminus terminus = new Terminus(new Ui(in), MainCommandParser.getInstance(),
TestFilePath.RESOURCE_DATA_FOLDER);
terminus.run();
terminus.start();
}

@Test
Expand Down

0 comments on commit f34071e

Please sign in to comment.