Skip to content

Commit c140c5e

Browse files
pesseSamuel Nitsche
authored andcommitted
Shutdown cli gracefully when known exceptions occur
Fixes #44
1 parent b972be1 commit c140c5e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/main/java/org/utplsql/cli/Cli.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.beust.jcommander.Parameter;
55
import com.beust.jcommander.ParameterException;
66
import org.utplsql.api.exception.DatabaseNotCompatibleException;
7+
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
8+
import org.utplsql.cli.exception.DatabaseConnectionFailed;
79

810
public class Cli {
911

@@ -35,7 +37,7 @@ public static void main(String[] args) {
3537
} else {
3638
jc.usage();
3739
}
38-
} catch ( DatabaseNotCompatibleException e ) {
40+
} catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
3941
System.out.println(e.getMessage());
4042
} catch (Exception e) {
4143
e.printStackTrace();

src/main/java/org/utplsql/cli/RunCommand.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.utplsql.api.exception.SomeTestsFailedException;
99
import org.utplsql.api.reporter.Reporter;
1010
import org.utplsql.api.reporter.ReporterFactory;
11+
import org.utplsql.cli.exception.DatabaseConnectionFailed;
1112

1213
import java.io.File;
1314
import java.io.FileNotFoundException;
@@ -120,8 +121,12 @@ public int run() throws Exception {
120121
reporterList = initReporters(conn, reporterOptionsList);
121122

122123
} catch (SQLException e) {
123-
System.out.println(e.getMessage());
124-
return Cli.DEFAULT_ERROR_CODE;
124+
if ( e.getErrorCode() == 1017 || e.getErrorCode() == 12514 ) {
125+
throw new DatabaseConnectionFailed(e);
126+
}
127+
else {
128+
throw e;
129+
}
125130
}
126131

127132
ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.utplsql.cli.exception;
2+
3+
import java.sql.SQLException;
4+
5+
public class DatabaseConnectionFailed extends SQLException {
6+
7+
public DatabaseConnectionFailed(SQLException cause ) {
8+
super( "Could not establish connection to database. Reason: " + cause.getMessage(), cause);
9+
}
10+
}

0 commit comments

Comments
 (0)