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
Next Next commit
Shutdown cli gracefully when known exceptions occur
Fixes #44
  • Loading branch information
pesse authored and Samuel Nitsche committed Nov 17, 2017
commit c140c5e58e02b90689a91734d926df16586f0dc6
4 changes: 3 additions & 1 deletion src/main/java/org/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import org.utplsql.cli.exception.DatabaseConnectionFailed;

public class Cli {

Expand Down Expand Up @@ -35,7 +37,7 @@ public static void main(String[] args) {
} else {
jc.usage();
}
} catch ( DatabaseNotCompatibleException e ) {
} catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
System.out.println(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.exception.DatabaseConnectionFailed;

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

} catch (SQLException e) {
System.out.println(e.getMessage());
return Cli.DEFAULT_ERROR_CODE;
if ( e.getErrorCode() == 1017 || e.getErrorCode() == 12514 ) {
throw new DatabaseConnectionFailed(e);
}
else {
throw e;
}
}

ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.utplsql.cli.exception;

import java.sql.SQLException;

public class DatabaseConnectionFailed extends SQLException {

public DatabaseConnectionFailed(SQLException cause ) {
super( "Could not establish connection to database. Reason: " + cause.getMessage(), cause);
}
}