Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Logger error behaviour and separate StorageManager from Logger #213

Merged
merged 1 commit into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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