Skip to content

Commit 77fb559

Browse files
committed
Add SqlServerErrorDetailsProvider
1 parent 0228f18 commit 77fb559

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

database-commons/src/main/java/io/cdap/plugin/util/DBUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public final class DBUtils {
6161

6262
public static final Calendar PURE_GREGORIAN_CALENDAR = createPureGregorianCalender();
6363
public static final String MYSQL_SUPPORTED_DOC_URL = "https://dev.mysql.com/doc/mysql-errors/9.0/en/";
64+
// mssql sel serverdoc url
65+
public static final String MSSQL_SUPPORTED_DOC_URL =
66+
"https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors";
6467
public static final String CLOUDSQLMYSQL_SUPPORTED_DOC_URL = "https://cloud.google.com/sql/docs/mysql/error-messages";
6568
public static final String POSTGRES_SUPPORTED_DOC_URL =
6669
"https://www.postgresql.org/docs/current/errcodes-appendix.html";
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright © 2025 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.mssql;
18+
19+
import io.cdap.cdap.api.exception.ErrorType;
20+
import io.cdap.plugin.db.DBErrorDetailsProvider;
21+
import io.cdap.plugin.util.DBUtils;
22+
23+
/**
24+
* A custom ErrorDetailsProvider for SQL Server plugins.
25+
*/
26+
public class SqlServerErrorDetailsProvider extends DBErrorDetailsProvider {
27+
28+
@Override
29+
protected String getExternalDocumentationLink() {
30+
return DBUtils.MSSQL_SUPPORTED_DOC_URL;
31+
}
32+
33+
@Override
34+
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
35+
if ((errorCode >= 50000 && errorCode <= 59999) || (errorCode >= 0 && errorCode <= 4999)) {
36+
// User-defined or low-level errors
37+
return ErrorType.USER;
38+
} else if (errorCode >= 60000 && errorCode <= 99999) {
39+
// System-level errors
40+
return ErrorType.SYSTEM;
41+
} else {
42+
// Errors outside the defined range
43+
return ErrorType.UNKNOWN;
44+
}
45+
}
46+
}

mssql-plugin/src/main/java/io/cdap/plugin/mssql/SqlServerSink.java

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

91+
@Override
92+
protected String getErrorDetailsProviderClassName() {
93+
return SqlServerErrorDetailsProvider.class.getName();
94+
}
95+
9196
/**
9297
* MSSQL action configuration.
9398
*/

mssql-plugin/src/main/java/io/cdap/plugin/mssql/SqlServerSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ protected Class<? extends DBWritable> getDBRecordType() {
7575
return SqlServerSourceDBRecord.class;
7676
}
7777

78+
@Override
79+
protected String getErrorDetailsProviderClassName() {
80+
return SqlServerErrorDetailsProvider.class.getName();
81+
}
82+
7883
@Override
7984
protected LineageRecorder getLineageRecorder(BatchSourceContext context) {
8085
String fqn = DBUtils.constructFQN("mssql",

0 commit comments

Comments
 (0)