From 17ab9fd56bd2aa92802a7954ab65138845c80822 Mon Sep 17 00:00:00 2001 From: Kelvin Neo <2332196+kelvneo@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:00:45 +0800 Subject: [PATCH] Change Logger error behaviour and separate StorageManager from Logger --- src/main/java/terminus/Terminus.java | 25 ++++++++++++++---------- src/test/java/terminus/TerminusTest.java | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/terminus/Terminus.java b/src/main/java/terminus/Terminus.java index ae99ff34bf..6f53bbe14a 100644 --- a/src/main/java/terminus/Terminus.java +++ b/src/main/java/terminus/Terminus.java @@ -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() { @@ -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(), @@ -88,7 +93,7 @@ void initialize() { TerminusLogger.info("Terminus has started."); } - + CommandResult handleUserInput(String input) { try { Command command = parser.parseCommand(input); diff --git a/src/test/java/terminus/TerminusTest.java b/src/test/java/terminus/TerminusTest.java index 2a88333a27..187f69cb2e 100644 --- a/src/test/java/terminus/TerminusTest.java +++ b/src/test/java/terminus/TerminusTest.java @@ -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