Skip to content

Commit 194d78f

Browse files
committed
Wrap SQLException in Abstract DBSource
1 parent 6bd8e3d commit 194d78f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

database-commons/src/main/java/io/cdap/plugin/db/source/AbstractDBSource.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import io.cdap.cdap.api.data.format.StructuredRecord;
2626
import io.cdap.cdap.api.data.schema.Schema;
2727
import io.cdap.cdap.api.dataset.lib.KeyValue;
28+
import io.cdap.cdap.api.exception.ErrorCategory;
29+
import io.cdap.cdap.api.exception.ErrorType;
30+
import io.cdap.cdap.api.exception.ErrorUtils;
2831
import io.cdap.cdap.api.plugin.PluginConfig;
2932
import io.cdap.cdap.etl.api.Emitter;
3033
import io.cdap.cdap.etl.api.FailureCollector;
@@ -196,7 +199,11 @@ private Schema loadSchemaFromDB(Class<? extends Driver> driverClass)
196199

197200
} catch (SQLException e) {
198201
// wrap exception to ensure SQLException-child instances not exposed to contexts without jdbc driver in classpath
199-
throw new SQLException(e.getMessage(), e.getSQLState(), e.getErrorCode());
202+
String errorMessageWithDetails = String.format("Error occurred while trying to get schema from database." +
203+
"Error message: '%s'. Error code: '%s'. SQLState: '%s'", e.getMessage(), e.getErrorCode(), e.getSQLState());
204+
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
205+
e.getMessage(), errorMessageWithDetails, ErrorType.USER, false, new SQLException(e.getMessage(),
206+
e.getSQLState(), e.getErrorCode()));
200207
} finally {
201208
driverCleanup.destroy();
202209
}

0 commit comments

Comments
 (0)