Skip to content

Commit 14d39c0

Browse files
committed
Exit with error on client exceptions
1 parent 349cc53 commit 14d39c0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/main/java/io/github/utplsql/cli/Cli.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
public class Cli {
88

9+
public static final int DEFAULT_ERROR_CODE = 1;
10+
911
public static final String HELP_CMD = "-h";
1012
public static final String RUN_CMD = "run";
1113

@@ -15,15 +17,15 @@ public static void main(String[] args) {
1517
RunCommand runCmd = new RunCommand();
1618
jc.addCommand(RUN_CMD, runCmd);
1719

20+
int exitCode = DEFAULT_ERROR_CODE;
21+
1822
try {
1923
jc.parse(args);
20-
boolean hasCmd = jc.getParsedCommand() != null;
2124

22-
if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) {
23-
int status = runCmd.run();
24-
System.exit(status);
25+
if (RUN_CMD.equals(jc.getParsedCommand())) {
26+
exitCode = runCmd.run();
2527
} else {
26-
jc.usage();
28+
throw new ParameterException("Command not specified.");
2729
}
2830
} catch (ParameterException e) {
2931
if (jc.getParsedCommand() != null) {
@@ -35,6 +37,8 @@ public static void main(String[] args) {
3537
} catch (Exception e) {
3638
e.printStackTrace();
3739
}
40+
41+
System.exit(exitCode);
3842
}
3943

4044
private static class HelpCommand {

src/main/java/io/github/utplsql/cli/RunCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public int run() throws Exception {
130130
reporterList.add(reporter);
131131
}
132132
} catch (SQLException e) {
133-
// TODO
134-
e.printStackTrace();
133+
System.out.println(e.getMessage());
134+
return Cli.DEFAULT_ERROR_CODE;
135135
}
136136

137137
ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());
@@ -150,8 +150,8 @@ public int run() throws Exception {
150150
} catch (SomeTestsFailedException e) {
151151
returnCode[0] = this.failureExitCode;
152152
} catch (SQLException e) {
153-
// TODO
154-
e.printStackTrace();
153+
System.out.println(e.getMessage());
154+
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
155155
}
156156
});
157157

@@ -173,8 +173,8 @@ public int run() throws Exception {
173173

174174
new OutputBuffer(ro.getReporterObj()).printAvailable(conn, printStreams);
175175
} catch (SQLException | FileNotFoundException e) {
176-
// TODO
177-
e.printStackTrace();
176+
System.out.println(e.getMessage());
177+
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
178178
} finally {
179179
if (fileOutStream != null)
180180
fileOutStream.close();

0 commit comments

Comments
 (0)