|
26 | 26 | import io.cdap.cdap.api.data.schema.Schema; |
27 | 27 | import io.cdap.cdap.api.dataset.lib.KeyValue; |
28 | 28 | import io.cdap.cdap.api.exception.ErrorCategory; |
| 29 | +import io.cdap.cdap.api.exception.ErrorCodeType; |
29 | 30 | import io.cdap.cdap.api.exception.ErrorType; |
30 | 31 | import io.cdap.cdap.api.exception.ErrorUtils; |
31 | 32 | import io.cdap.cdap.api.plugin.PluginConfig; |
@@ -202,8 +203,17 @@ private Schema loadSchemaFromDB(Class<? extends Driver> driverClass) |
202 | 203 | // wrap exception to ensure SQLException-child instances not exposed to contexts without jdbc driver in classpath |
203 | 204 | String errorMessageWithDetails = String.format("Error occurred while trying to get schema from database." + |
204 | 205 | "Error message: '%s'. Error code: '%s'. SQLState: '%s'", e.getMessage(), e.getErrorCode(), e.getSQLState()); |
| 206 | + String externalDocumentationLink = getExternalDocumentationLink(); |
| 207 | + if (!Strings.isNullOrEmpty(externalDocumentationLink)) { |
| 208 | + if (!errorMessageWithDetails.endsWith(".")) { |
| 209 | + errorMessageWithDetails = errorMessageWithDetails + "."; |
| 210 | + } |
| 211 | + errorMessageWithDetails = String.format("%s For more details, see %s", errorMessageWithDetails, |
| 212 | + externalDocumentationLink); |
| 213 | + } |
205 | 214 | throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), |
206 | | - e.getMessage(), errorMessageWithDetails, ErrorType.USER, false, new SQLException(e.getMessage(), |
| 215 | + e.getMessage(), errorMessageWithDetails, ErrorType.USER, false, ErrorCodeType.SQLSTATE, |
| 216 | + e.getSQLState(), externalDocumentationLink, new SQLException(e.getMessage(), |
207 | 217 | e.getSQLState(), e.getErrorCode())); |
208 | 218 | } finally { |
209 | 219 | driverCleanup.destroy(); |
@@ -363,6 +373,10 @@ protected Class<? extends DBWritable> getDBRecordType() { |
363 | 373 | return DBRecord.class; |
364 | 374 | } |
365 | 375 |
|
| 376 | + protected String getExternalDocumentationLink() { |
| 377 | + return null; |
| 378 | + } |
| 379 | + |
366 | 380 | @Override |
367 | 381 | public void initialize(BatchRuntimeContext context) throws Exception { |
368 | 382 | super.initialize(context); |
|
0 commit comments