Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import io.cdap.plugin.db.ConnectionConfig;
import io.cdap.plugin.db.ConnectionConfigAccessor;
import io.cdap.plugin.db.DBConfig;
import io.cdap.plugin.db.DBErrorDetailsProvider;
import io.cdap.plugin.db.DBRecord;
import io.cdap.plugin.db.Operation;
import io.cdap.plugin.db.SchemaReader;
Expand Down Expand Up @@ -313,18 +312,20 @@ private Schema inferSchema(Class<? extends Driver> driverClass) {
}
} catch (SQLException e) {
// wrap exception to ensure SQLException-child instances not exposed to contexts w/o jdbc driver in classpath
String errorMessage =
String.format("SQL Exception occurred: [Message='%s', SQLState='%s', ErrorCode='%s'].", e.getMessage(),
e.getSQLState(), e.getErrorCode());
String errorMessageWithDetails = String.format("Error while reading table metadata." +
"Error message: '%s'. Error code: '%s'. SQLState: '%s'", e.getMessage(), e.getErrorCode(), e.getSQLState());
String externalDocumentationLink = getExternalDocumentationLink();
if (!Strings.isNullOrEmpty(externalDocumentationLink)) {
if (!errorMessageWithDetails.endsWith(".")) {
errorMessageWithDetails = errorMessageWithDetails + ".";
if (!errorMessage.endsWith(".")) {
errorMessage = errorMessage + ".";
}
errorMessageWithDetails = String.format("%s For more details, see %s", errorMessageWithDetails,
externalDocumentationLink);
errorMessage = String.format("%s For more details, see %s", errorMessageWithDetails, errorMessage);
}
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
e.getMessage(), errorMessageWithDetails, ErrorType.USER, false, ErrorCodeType.SQLSTATE,
errorMessage, errorMessageWithDetails, ErrorType.USER, false, ErrorCodeType.SQLSTATE,
e.getSQLState(), externalDocumentationLink, new SQLException(e.getMessage(),
e.getSQLState(), e.getErrorCode()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import io.cdap.plugin.db.ConnectionConfig;
import io.cdap.plugin.db.ConnectionConfigAccessor;
import io.cdap.plugin.db.DBConfig;
import io.cdap.plugin.db.DBErrorDetailsProvider;
import io.cdap.plugin.db.DBRecord;
import io.cdap.plugin.db.SchemaReader;
import io.cdap.plugin.db.TransactionIsolationLevel;
Expand Down Expand Up @@ -201,18 +200,20 @@ private Schema loadSchemaFromDB(Class<? extends Driver> driverClass)

} catch (SQLException e) {
// wrap exception to ensure SQLException-child instances not exposed to contexts without jdbc driver in classpath
String errorMessage =
String.format("SQL Exception occurred: [Message='%s', SQLState='%s', ErrorCode='%s'].", e.getMessage(),
e.getSQLState(), e.getErrorCode());
String errorMessageWithDetails = String.format("Error occurred while trying to get schema from database." +
"Error message: '%s'. Error code: '%s'. SQLState: '%s'", e.getMessage(), e.getErrorCode(), e.getSQLState());
String externalDocumentationLink = getExternalDocumentationLink();
if (!Strings.isNullOrEmpty(externalDocumentationLink)) {
if (!errorMessageWithDetails.endsWith(".")) {
errorMessageWithDetails = errorMessageWithDetails + ".";
if (!errorMessage.endsWith(".")) {
errorMessage = errorMessage + ".";
}
errorMessageWithDetails = String.format("%s For more details, see %s", errorMessageWithDetails,
externalDocumentationLink);
errorMessage = String.format("%s For more details, see %s", errorMessage, externalDocumentationLink);
}
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
e.getMessage(), errorMessageWithDetails, ErrorType.USER, false, ErrorCodeType.SQLSTATE,
errorMessage, errorMessageWithDetails, ErrorType.USER, false, ErrorCodeType.SQLSTATE,
e.getSQLState(), externalDocumentationLink, new SQLException(e.getMessage(),
e.getSQLState(), e.getErrorCode()));
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.cdap.plugin.mysql;

import io.cdap.cdap.api.exception.ErrorType;
import io.cdap.plugin.db.DBErrorDetailsProvider;
import io.cdap.plugin.common.db.DBErrorDetailsProvider;
import io.cdap.plugin.util.DBUtils;

/**
Expand All @@ -31,7 +31,7 @@ protected String getExternalDocumentationLink() {
}

@Override
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
protected ErrorType getErrorTypeFromErrorCodeAndSqlState(int errorCode, String sqlState) {
// https://dev.mysql.com/doc/refman/9.0/en/error-message-elements.html#error-code-ranges
if (errorCode >= 1000 && errorCode <= 5999) {
return ErrorType.USER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.common.base.Strings;
import io.cdap.cdap.api.exception.ErrorCategory;
import io.cdap.cdap.api.exception.ErrorType;
import io.cdap.plugin.db.DBErrorDetailsProvider;
import io.cdap.plugin.common.db.DBErrorDetailsProvider;
import io.cdap.plugin.util.DBUtils;

import java.util.HashMap;
Expand Down Expand Up @@ -77,7 +77,7 @@ protected String getExternalDocumentationLink() {
}

@Override
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
protected ErrorType getErrorTypeFromErrorCodeAndSqlState(int errorCode, String sqlState) {
if (!Strings.isNullOrEmpty(sqlState) && sqlState.length() >= 2 &&
ERROR_CODE_TO_ERROR_TYPE.containsKey(sqlState.substring(0, 2))) {
return ERROR_CODE_TO_ERROR_TYPE.get(sqlState.substring(0, 2));
Expand Down
Loading