Skip to content

Commit 05a33c6

Browse files
committed
Add PostgresErrorDetailsProvider
1 parent 23af441 commit 05a33c6

File tree

8 files changed

+64
-4
lines changed

8 files changed

+64
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private ProgramFailureException getProgramFailureException(SQLException e, Error
7676
externalDocumentationLink);
7777
}
7878
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
79-
errorMessage, errorMessageWithDetails, getErrorTypeFromErrorCode(errorCode), false, e);
79+
errorMessage, errorMessageWithDetails, getErrorTypeFromErrorCode(errorCode, sqlState), false, e);
8080
}
8181

8282
/**
@@ -118,7 +118,7 @@ protected String getExternalDocumentationLink() {
118118
return null;
119119
}
120120

121-
protected ErrorType getErrorTypeFromErrorCode(int errorCode) {
121+
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
122122
return ErrorType.UNKNOWN;
123123
}
124124
}

mysql-plugin/src/main/java/io/cdap/plugin/mysql/MysqlErrorDetailsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected String getExternalDocumentationLink() {
3030
}
3131

3232
@Override
33-
protected ErrorType getErrorTypeFromErrorCode(int errorCode) {
33+
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
3434
// https://dev.mysql.com/doc/refman/9.0/en/error-message-elements.html#error-code-ranges
3535
if (errorCode >= 1000 && errorCode <= 5999) {
3636
return ErrorType.USER;

postgresql-plugin/src/e2e-test/features/postgresql/source/PostgresqlRunTime.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ Feature: PostgreSQL - Verify data transfer from PostgreSQL source to BigQuery si
147147
And Save and Deploy Pipeline
148148
And Run the Pipeline in Runtime
149149
And Wait till pipeline is in running state
150+
And Open and capture logs
150151
And Verify the pipeline status is "Failed"
152+
And Close the pipeline logs
151153
Then Open Pipeline logs and verify Log entries having below listed Level and Message:
152154
| Level | Message |
153155
| ERROR | errorLogsMessageInvalidBoundingQuery |

postgresql-plugin/src/e2e-test/features/postgresql/source/PostgresqlRunTimeMacro.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Feature: PostgreSQL - Verify PostgreSQL plugin data transfer with macro argument
171171
Then Enter runtime argument value "invalidUserName" for key "PostgreSQLUsername"
172172
Then Enter runtime argument value "invalidPassword" for key "PostgreSQLPassword"
173173
Then Run the preview of pipeline with runtime arguments
174+
Then Open and capture pipeline preview logs
174175
Then Verify the preview of pipeline is "Failed"
175176

176177
@POSTGRESQL_SOURCE_TEST @Postgresql_Required @POSTGRESQL_SINK_TEST
@@ -210,6 +211,7 @@ Feature: PostgreSQL - Verify PostgreSQL plugin data transfer with macro argument
210211
Then Enter runtime argument value "invalidTable" for key "PostgreSQLTableName"
211212
Then Enter runtime argument value "schema" for key "PostgreSQLSchemaName"
212213
Then Run the preview of pipeline with runtime arguments
214+
Then Open and capture pipeline preview logs
213215
Then Verify the preview of pipeline is "Failed"
214216

215217
@POSTGRESQL_SOURCE_TEST @POSTGRESQL_SINK_TEST @BQ_SINK_TEST @Plugin-1526

postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresConstants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616

1717
package io.cdap.plugin.postgres;
1818

19+
import io.cdap.cdap.api.exception.ErrorCategory;
20+
import io.cdap.cdap.api.exception.ErrorType;
21+
import io.cdap.cdap.api.exception.ErrorUtils;
22+
1923
/**
2024
* Postgres constants.
2125
*/
2226
public final class PostgresConstants {
2327

2428
private PostgresConstants() {
25-
throw new AssertionError("Should not instantiate static utility class.");
29+
String errorMessage = "Should not instantiate static utility class.";
30+
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
31+
errorMessage, errorMessage, ErrorType.SYSTEM, false, new AssertionError(errorMessage));
2632
}
2733

2834
public static final String PLUGIN_NAME = "Postgres";
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.cdap.plugin.postgres;
18+
19+
import io.cdap.cdap.api.exception.ErrorType;
20+
import io.cdap.plugin.db.DBErrorDetailsProvider;
21+
22+
/**
23+
* A custom ErrorDetailsProvider for Postgres plugins.
24+
*/
25+
public class PostgresErrorDetailsProvider extends DBErrorDetailsProvider {
26+
@Override
27+
protected String getExternalDocumentationLink() {
28+
return "https://www.postgresql.org/docs/current/errcodes-appendix.html";
29+
}
30+
31+
@Override
32+
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
33+
if (sqlState.startsWith("42")) {
34+
return ErrorType.USER;
35+
} else if (sqlState.startsWith("08")) {
36+
return ErrorType.SYSTEM;
37+
}
38+
return ErrorType.UNKNOWN;
39+
}
40+
}

postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresSink.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ protected LineageRecorder getLineageRecorder(BatchSinkContext context) {
116116
return new LineageRecorder(context, asset);
117117
}
118118

119+
@Override
120+
protected String getErrorDetailsProviderClassName() {
121+
return PostgresErrorDetailsProvider.class.getName();
122+
}
123+
119124
/**
120125
* PostgreSQL action configuration.
121126
*/

postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ protected SchemaReader getSchemaReader() {
6767
return new PostgresSchemaReader();
6868
}
6969

70+
@Override
71+
protected String getErrorDetailsProviderClassName() {
72+
return PostgresErrorDetailsProvider.class.getName();
73+
}
74+
7075
@Override
7176
protected Class<? extends DBWritable> getDBRecordType() {
7277
return PostgresDBRecord.class;

0 commit comments

Comments
 (0)