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

return non-zero exit code on checker errors #108

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 19 additions & 0 deletions src/main/java/etc/ExitCode.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
12 changes: 7 additions & 5 deletions src/main/java/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down