diff --git a/src/main/java/etc/ExitCode.java b/src/main/java/etc/ExitCode.java new file mode 100644 index 0000000..e9b8e9f --- /dev/null +++ b/src/main/java/etc/ExitCode.java @@ -0,0 +1,19 @@ +package etc; + +public enum ExitCode { + + NORMAL(0), + GENERIC_ERROR(1), + CHECKER_ERROR(2); + + private int code; + + private ExitCode(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + +} diff --git a/src/main/java/main/Main.java b/src/main/java/main/Main.java index 7a68e6f..97ce02d 100644 --- a/src/main/java/main/Main.java +++ b/src/main/java/main/Main.java @@ -10,6 +10,7 @@ import checker.IChecker; import checker.MiLoGChecker; import data.TimeSheet; +import etc.ExitCode; import i18n.ResourceHandler; import io.FileController; import io.IGenerator; @@ -35,7 +36,7 @@ public static void main(String[] args) { request = userInput.parse(); } catch (org.apache.commons.cli.ParseException e) { System.out.println(e.getMessage()); - System.exit(1); + System.exit(ExitCode.GENERIC_ERROR.getCode()); return; } @@ -58,7 +59,7 @@ public static void main(String[] args) { month = FileController.readFileToString(userInput.getFile(UserInputFile.JSON_MONTH)); } catch (IOException e) { System.out.println(e.getMessage()); - System.exit(1); + System.exit(ExitCode.GENERIC_ERROR.getCode()); return; } @@ -68,7 +69,7 @@ public static void main(String[] args) { timeSheet = Parser.parseTimeSheetJson(global, month); } catch (ParseException e) { System.out.println(e.getMessage()); - System.exit(1); + System.exit(ExitCode.GENERIC_ERROR.getCode()); return; } @@ -79,7 +80,7 @@ public static void main(String[] args) { checkerReturn = checker.check(); } catch (CheckerException e) { // exception does not mean that the time sheet is invalid, but that the process of checking failed System.out.println(e.getMessage()); - System.exit(1); + System.exit(ExitCode.GENERIC_ERROR.getCode()); return; } // Print all errors in case the time sheet is invalid @@ -97,6 +98,7 @@ public static void main(String[] args) { JOptionPane.showMessageDialog(null, errorList.toString(), ResourceHandler.getMessage("gui.errorListWindowTitle"), JOptionPane.ERROR_MESSAGE); } + System.exit(ExitCode.CHECKER_ERROR.getCode()); return; } @@ -108,7 +110,7 @@ public static void main(String[] args) { FileController.saveStringToFile(generator.generate(), userInput.getFile(UserInputFile.OUTPUT)); } catch (IOException e) { System.out.println(e.getMessage()); - System.exit(1); + System.exit(ExitCode.GENERIC_ERROR.getCode()); return; } }