Skip to content

Commit

Permalink
Merge pull request #91 from kelvneo/bug-InvalidJSON
Browse files Browse the repository at this point in the history
Fix error in invalid JSON file
  • Loading branch information
3m0W33D authored Oct 12, 2021
2 parents 18ab7d9 + 5f1acc4 commit db8c150
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/terminus/Terminus.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package terminus;

import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.nio.file.Path;
import terminus.command.Command;
Expand All @@ -15,6 +17,12 @@

public class Terminus {

public static final String[] INVALID_JSON_MESSAGE = {
"Invalid file data detected.",
"TermiNUS will still run, but the file will be overwritten when the next command is ran.",
"To save your current file, close your terminal (do not run exit).",
"Otherwise, you can continue using the program :)"
};
private Ui ui;
private CommandParser parser;
private String workspace;
Expand Down Expand Up @@ -54,8 +62,11 @@ private void start() {
TerminusLogger.info("Loading file...");
this.nusModule = moduleStorage.loadFile();
} catch (IOException e) {
TerminusLogger.warning("File loading has failed.");
TerminusLogger.warning("File loading has failed.", e.fillInStackTrace());
handleIoException(e);
} catch (JsonSyntaxException | JsonIOException e) {
TerminusLogger.severe("Invalid file data detected!", e.fillInStackTrace());
ui.printSection(INVALID_JSON_MESSAGE);
} finally {
if (this.nusModule == null) {
TerminusLogger.warning("File not found.");
Expand Down Expand Up @@ -97,10 +108,10 @@ private void runCommandsUntilExit() {
this.moduleStorage.saveFile(nusModule);
TerminusLogger.info("Save completed.");
} catch (InvalidCommandException e) {
TerminusLogger.warning("Invalid input provided: " + input, e.getCause());
TerminusLogger.warning("Invalid input provided: " + input, e.fillInStackTrace());
ui.printSection(e.getMessage());
} catch (InvalidArgumentException e) {
TerminusLogger.warning("Invalid input provided: " + input, e.getCause());
TerminusLogger.warning("Invalid input provided: " + input, e.fillInStackTrace());

// Check if the exception specified a correct command format for the user to follow.
if (e.getFormat() != null) {
Expand Down

0 comments on commit db8c150

Please sign in to comment.