This is an automated email from the ASF dual-hosted git repository.

gaojun2048 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new eb42d629a [Improve][Connector-V2][GoogleSheets] Unified exception for 
GoogleSheets source connector (#3524)
eb42d629a is described below

commit eb42d629ad1055b79301ffa2be35586441a17ffe
Author: ChunFu Wu <[email protected]>
AuthorDate: Thu Nov 24 16:19:54 2022 +0800

    [Improve][Connector-V2][GoogleSheets] Unified exception for GoogleSheets 
source connector (#3524)
---
 .../deserialize/GoogleSheetsDeserializer.java      |  7 +++--
 .../exception/GoogleSheetsConnectorException.java  | 36 ++++++++++++++++++++++
 .../google/sheets/source/SheetsSource.java         |  6 +++-
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git 
a/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/deserialize/GoogleSheetsDeserializer.java
 
b/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/deserialize/GoogleSheetsDeserializer.java
index d86e45969..95caf711b 100644
--- 
a/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/deserialize/GoogleSheetsDeserializer.java
+++ 
b/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/deserialize/GoogleSheetsDeserializer.java
@@ -19,6 +19,8 @@ package 
org.apache.seatunnel.connectors.seatunnel.google.sheets.deserialize;
 
 import org.apache.seatunnel.api.serialization.DeserializationSchema;
 import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import 
org.apache.seatunnel.connectors.seatunnel.google.sheets.exception.GoogleSheetsConnectorException;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 
@@ -29,7 +31,7 @@ import java.util.Map;
 
 public class GoogleSheetsDeserializer implements SeaTunnelRowDeserializer {
 
-    private DeserializationSchema<SeaTunnelRow> deserializationSchema;
+    private final DeserializationSchema<SeaTunnelRow> deserializationSchema;
     private final ObjectMapper objectMapper = new ObjectMapper();
     private final String[] fields;
 
@@ -50,7 +52,8 @@ public class GoogleSheetsDeserializer implements 
SeaTunnelRowDeserializer {
             String rowStr = objectMapper.writeValueAsString(map);
             return deserializationSchema.deserialize(rowStr.getBytes());
         } catch (IOException e) {
-            throw new RuntimeException("Object json deserialization 
exception.", e);
+            throw new 
GoogleSheetsConnectorException(CommonErrorCode.JSON_OPERATION_FAILED,
+                "Object json deserialization failed.", e);
         }
     }
 }
diff --git 
a/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/exception/GoogleSheetsConnectorException.java
 
b/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/exception/GoogleSheetsConnectorException.java
new file mode 100644
index 000000000..7f9c66216
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/exception/GoogleSheetsConnectorException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.google.sheets.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class GoogleSheetsConnectorException extends SeaTunnelRuntimeException {
+
+    public GoogleSheetsConnectorException(SeaTunnelErrorCode 
seaTunnelErrorCode, String errorMessage) {
+        super(seaTunnelErrorCode, errorMessage);
+    }
+
+    public GoogleSheetsConnectorException(SeaTunnelErrorCode 
seaTunnelErrorCode, String errorMessage, Throwable cause) {
+        super(seaTunnelErrorCode, errorMessage, cause);
+    }
+
+    public GoogleSheetsConnectorException(SeaTunnelErrorCode 
seaTunnelErrorCode, Throwable cause) {
+        super(seaTunnelErrorCode, cause);
+    }
+}
diff --git 
a/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSource.java
 
b/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSource.java
index 582f16631..64f674fdd 100644
--- 
a/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSource.java
+++ 
b/seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSource.java
@@ -18,6 +18,7 @@
 package org.apache.seatunnel.connectors.seatunnel.google.sheets.source;
 
 import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
 import org.apache.seatunnel.api.serialization.DeserializationSchema;
 import org.apache.seatunnel.api.source.Boundedness;
 import org.apache.seatunnel.api.source.SeaTunnelSource;
@@ -33,6 +34,7 @@ import 
org.apache.seatunnel.connectors.seatunnel.common.source.AbstractSingleSpl
 import 
org.apache.seatunnel.connectors.seatunnel.common.source.SingleSplitReaderContext;
 import 
org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsConfig;
 import 
org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsParameters;
+import 
org.apache.seatunnel.connectors.seatunnel.google.sheets.exception.GoogleSheetsConnectorException;
 import org.apache.seatunnel.format.json.JsonDeserializationSchema;
 
 import org.apache.seatunnel.shade.com.typesafe.config.Config;
@@ -57,7 +59,9 @@ public class SheetsSource extends 
AbstractSingleSplitSource<SeaTunnelRow> {
     public void prepare(Config pluginConfig) throws PrepareFailException {
         CheckResult checkResult = CheckConfigUtil.checkAllExists(pluginConfig, 
SheetsConfig.SERVICE_ACCOUNT_KEY.key(), SheetsConfig.SHEET_ID.key(), 
SheetsConfig.SHEET_NAME.key(), SheetsConfig.RANGE.key(), 
SeaTunnelSchema.SCHEMA.key());
         if (!checkResult.isSuccess()) {
-            throw new PrepareFailException(getPluginName(), PluginType.SOURCE, 
checkResult.getMsg());
+            throw new 
GoogleSheetsConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                String.format("PluginName: %s, PluginType: %s, Message: %s",
+                    getPluginName(), PluginType.SOURCE, checkResult.getMsg()));
         }
         this.sheetsParameters = new 
SheetsParameters().buildWithConfig(pluginConfig);
         if (pluginConfig.hasPath(SeaTunnelSchema.SCHEMA.key())) {

Reply via email to