Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Exit with error on client exceptions
  • Loading branch information
viniciusam committed Jul 21, 2017
commit 14d39c0295a435ed1ed32f18c7bc1991a9fb3046
14 changes: 9 additions & 5 deletions src/main/java/io/github/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class Cli {

public static final int DEFAULT_ERROR_CODE = 1;

public static final String HELP_CMD = "-h";
public static final String RUN_CMD = "run";

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

int exitCode = DEFAULT_ERROR_CODE;

try {
jc.parse(args);
boolean hasCmd = jc.getParsedCommand() != null;

if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) {
int status = runCmd.run();
System.exit(status);
if (RUN_CMD.equals(jc.getParsedCommand())) {
exitCode = runCmd.run();
} else {
jc.usage();
throw new ParameterException("Command not specified.");
}
} catch (ParameterException e) {
if (jc.getParsedCommand() != null) {
Expand All @@ -35,6 +37,8 @@ public static void main(String[] args) {
} catch (Exception e) {
e.printStackTrace();
}

System.exit(exitCode);
}

private static class HelpCommand {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/github/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public int run() throws Exception {
reporterList.add(reporter);
}
} catch (SQLException e) {
// TODO
e.printStackTrace();
System.out.println(e.getMessage());
return Cli.DEFAULT_ERROR_CODE;
}

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

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

new OutputBuffer(ro.getReporterObj()).printAvailable(conn, printStreams);
} catch (SQLException | FileNotFoundException e) {
// TODO
e.printStackTrace();
System.out.println(e.getMessage());
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
} finally {
if (fileOutStream != null)
fileOutStream.close();
Expand Down