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

JDBC Sources: Wrap SQLTransientException with ConfigErrorException #19711

Merged
merged 15 commits into from
Dec 1, 2022
Merged
Changes from 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.airbyte.db.jdbc;

import com.google.errorprone.annotations.MustBeClosed;
import io.airbyte.commons.exceptions.ConfigErrorException;
import io.airbyte.commons.exceptions.ConnectionErrorException;
import io.airbyte.commons.functional.CheckedConsumer;
import io.airbyte.commons.functional.CheckedFunction;
Expand All @@ -14,6 +15,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLTransientException;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -79,6 +81,12 @@ public DatabaseMetaData getMetaData() throws SQLException {
final DatabaseMetaData metaData = connection.getMetaData();
return metaData;
} catch (final SQLException e) {
if (e instanceof SQLTransientException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build error is linting. Make a separate catch statement

Task :airbyte-db:db-lib:pmdMain FAILED
/actions-runner/_work/airbyte/airbyte/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/DefaultJdbcDatabase.java:84: AvoidInstanceofChecksInCatchClause: An instanceof check is being performed on the caught exception. Create a separate catch clause for this exception type.

final String message = e.getMessage();
if (message.contains("request timed out")) {
throw new ConfigErrorException("Connection timed out. Unable to contact server. Please check your server settings or try again later", e);
}
}
// Some databases like Redshift will have null cause
if (Objects.isNull(e.getCause()) || !(e.getCause() instanceof SQLException)) {
throw new ConnectionErrorException(e.getSQLState(), e.getErrorCode(), e.getMessage(), e);
Expand Down