Skip to content

Commit eb42d62

Browse files
authored
[Improve][Connector-V2][GoogleSheets] Unified exception for GoogleSheets source connector (#3524)
1 parent 58584ee commit eb42d62

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/deserialize/GoogleSheetsDeserializer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import org.apache.seatunnel.api.serialization.DeserializationSchema;
2121
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
22+
import org.apache.seatunnel.common.exception.CommonErrorCode;
23+
import org.apache.seatunnel.connectors.seatunnel.google.sheets.exception.GoogleSheetsConnectorException;
2224

2325
import com.fasterxml.jackson.databind.ObjectMapper;
2426

@@ -29,7 +31,7 @@
2931

3032
public class GoogleSheetsDeserializer implements SeaTunnelRowDeserializer {
3133

32-
private DeserializationSchema<SeaTunnelRow> deserializationSchema;
34+
private final DeserializationSchema<SeaTunnelRow> deserializationSchema;
3335
private final ObjectMapper objectMapper = new ObjectMapper();
3436
private final String[] fields;
3537

@@ -50,7 +52,8 @@ public SeaTunnelRow deserializeRow(List<Object> row) {
5052
String rowStr = objectMapper.writeValueAsString(map);
5153
return deserializationSchema.deserialize(rowStr.getBytes());
5254
} catch (IOException e) {
53-
throw new RuntimeException("Object json deserialization exception.", e);
55+
throw new GoogleSheetsConnectorException(CommonErrorCode.JSON_OPERATION_FAILED,
56+
"Object json deserialization failed.", e);
5457
}
5558
}
5659
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.connectors.seatunnel.google.sheets.exception;
19+
20+
import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
21+
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
22+
23+
public class GoogleSheetsConnectorException extends SeaTunnelRuntimeException {
24+
25+
public GoogleSheetsConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, String errorMessage) {
26+
super(seaTunnelErrorCode, errorMessage);
27+
}
28+
29+
public GoogleSheetsConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, String errorMessage, Throwable cause) {
30+
super(seaTunnelErrorCode, errorMessage, cause);
31+
}
32+
33+
public GoogleSheetsConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, Throwable cause) {
34+
super(seaTunnelErrorCode, cause);
35+
}
36+
}

seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.seatunnel.connectors.seatunnel.google.sheets.source;
1919

2020
import org.apache.seatunnel.api.common.PrepareFailException;
21+
import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
2122
import org.apache.seatunnel.api.serialization.DeserializationSchema;
2223
import org.apache.seatunnel.api.source.Boundedness;
2324
import org.apache.seatunnel.api.source.SeaTunnelSource;
@@ -33,6 +34,7 @@
3334
import org.apache.seatunnel.connectors.seatunnel.common.source.SingleSplitReaderContext;
3435
import org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsConfig;
3536
import org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsParameters;
37+
import org.apache.seatunnel.connectors.seatunnel.google.sheets.exception.GoogleSheetsConnectorException;
3638
import org.apache.seatunnel.format.json.JsonDeserializationSchema;
3739

3840
import org.apache.seatunnel.shade.com.typesafe.config.Config;
@@ -57,7 +59,9 @@ public String getPluginName() {
5759
public void prepare(Config pluginConfig) throws PrepareFailException {
5860
CheckResult checkResult = CheckConfigUtil.checkAllExists(pluginConfig, SheetsConfig.SERVICE_ACCOUNT_KEY.key(), SheetsConfig.SHEET_ID.key(), SheetsConfig.SHEET_NAME.key(), SheetsConfig.RANGE.key(), SeaTunnelSchema.SCHEMA.key());
5961
if (!checkResult.isSuccess()) {
60-
throw new PrepareFailException(getPluginName(), PluginType.SOURCE, checkResult.getMsg());
62+
throw new GoogleSheetsConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
63+
String.format("PluginName: %s, PluginType: %s, Message: %s",
64+
getPluginName(), PluginType.SOURCE, checkResult.getMsg()));
6165
}
6266
this.sheetsParameters = new SheetsParameters().buildWithConfig(pluginConfig);
6367
if (pluginConfig.hasPath(SeaTunnelSchema.SCHEMA.key())) {

0 commit comments

Comments
 (0)