diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/PrepareFailException.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/PrepareFailException.java index 7cb75b98fed3..6afbc4e7620b 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/PrepareFailException.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/PrepareFailException.java @@ -18,21 +18,22 @@ package org.apache.seatunnel.api.common; import org.apache.seatunnel.common.constants.PluginType; +import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; import org.apache.seatunnel.shade.com.typesafe.config.Config; /** * This exception will throw when {@link SeaTunnelPluginLifeCycle#prepare(Config)} failed. */ -public class PrepareFailException extends RuntimeException { +public class PrepareFailException extends SeaTunnelRuntimeException { public PrepareFailException(String pluginName, PluginType type, String message) { - super(String.format("PluginName: %s, PluginType: %s, Message: %s", pluginName, type.getType(), - message)); + super(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED, String.format("PluginName: %s, PluginType: %s, Message: %s", + pluginName, type.getType(), message)); } public PrepareFailException(String pluginName, PluginType type, String message, Throwable cause) { - super(String.format("PluginName: %s, PluginType: %s, Message: %s", pluginName, type.getType(), - message), cause); + super(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED, String.format("PluginName: %s, PluginType: %s, Message: %s", + pluginName, type.getType(), message), cause); } } diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/SeaTunnelAPIErrorCode.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/SeaTunnelAPIErrorCode.java new file mode 100644 index 000000000000..de2dc66e98d9 --- /dev/null +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/common/SeaTunnelAPIErrorCode.java @@ -0,0 +1,47 @@ +/* + * 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.api.common; + +import org.apache.seatunnel.common.exception.SeaTunnelErrorCode; + +public enum SeaTunnelAPIErrorCode implements SeaTunnelErrorCode { + CONFIG_VALIDATION_FAILED("API-01", "Configuration item validation failure"), + OPTION_VALIDATION_FAILED("API-02", "Option item validation failure"), + CATALOG_ERROR("API-03", "Catalog related failure"), + DATABASE_NOT_FOUND("API-04", "Database not found"), + TABLE_NOT_FOUND("API-05", "Table not found"), + FACTORY_INITIALIZATION_FAILED("API-06", "Factory initialization failure"),; + + private final String code; + private final String description; + + SeaTunnelAPIErrorCode(String code, String description) { + this.code = code; + this.description = description; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getDescription() { + return description; + } +} diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/util/OptionValidationException.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/util/OptionValidationException.java index a5928625afef..2abe052d732d 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/util/OptionValidationException.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/util/OptionValidationException.java @@ -17,16 +17,19 @@ package org.apache.seatunnel.api.configuration.util; +import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode; +import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; + /** * Exception for all errors occurring during option validation phase. */ -public class OptionValidationException extends RuntimeException { +public class OptionValidationException extends SeaTunnelRuntimeException { public OptionValidationException(String message, Throwable cause) { - super(message, cause); + super(SeaTunnelAPIErrorCode.OPTION_VALIDATION_FAILED, message, cause); } public OptionValidationException(String message) { - super(message); + super(SeaTunnelAPIErrorCode.OPTION_VALIDATION_FAILED, message); } } diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/CatalogException.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/CatalogException.java index d91e6670e8d0..e923ea0d441b 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/CatalogException.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/CatalogException.java @@ -17,23 +17,26 @@ package org.apache.seatunnel.api.table.catalog.exception; +import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode; +import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; + /** * A catalog-related, runtime exception. */ -public class CatalogException extends RuntimeException { +public class CatalogException extends SeaTunnelRuntimeException { /** * @param message the detail message. */ public CatalogException(String message) { - super(message); + super(SeaTunnelAPIErrorCode.CATALOG_ERROR, message); } /** * @param cause the cause. */ public CatalogException(Throwable cause) { - super(cause); + super(SeaTunnelAPIErrorCode.CATALOG_ERROR, cause); } /** @@ -41,6 +44,6 @@ public CatalogException(Throwable cause) { * @param cause the cause. */ public CatalogException(String message, Throwable cause) { - super(message, cause); + super(SeaTunnelAPIErrorCode.CATALOG_ERROR, message, cause); } } diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/DatabaseNotExistException.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/DatabaseNotExistException.java index 5e81505f7c55..e38564ec3644 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/DatabaseNotExistException.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/DatabaseNotExistException.java @@ -18,12 +18,15 @@ package org.apache.seatunnel.api.table.catalog.exception; +import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode; +import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; + /** Exception for trying to operate on a database that doesn't exist. */ -public class DatabaseNotExistException extends Exception { +public class DatabaseNotExistException extends SeaTunnelRuntimeException { private static final String MSG = "Database %s does not exist in Catalog %s."; public DatabaseNotExistException(String catalogName, String databaseName, Throwable cause) { - super(String.format(MSG, databaseName, catalogName), cause); + super(SeaTunnelAPIErrorCode.DATABASE_NOT_FOUND, String.format(MSG, databaseName, catalogName), cause); } public DatabaseNotExistException(String catalogName, String databaseName) { diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/TableNotExistException.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/TableNotExistException.java index d37a586eb800..e3ca44698282 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/TableNotExistException.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/exception/TableNotExistException.java @@ -18,10 +18,12 @@ package org.apache.seatunnel.api.table.catalog.exception; +import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode; import org.apache.seatunnel.api.table.catalog.TablePath; +import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; /** Exception for trying to operate on a table that doesn't exist. */ -public class TableNotExistException extends Exception { +public class TableNotExistException extends SeaTunnelRuntimeException { private static final String MSG = "Table %s does not exist in Catalog %s."; @@ -30,6 +32,6 @@ public TableNotExistException(String catalogName, TablePath tablePath) { } public TableNotExistException(String catalogName, TablePath tablePath, Throwable cause) { - super(String.format(MSG, tablePath.getFullName(), catalogName), cause); + super(SeaTunnelAPIErrorCode.TABLE_NOT_FOUND, String.format(MSG, tablePath.getFullName(), catalogName), cause); } } diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/factory/FactoryException.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/factory/FactoryException.java index 64e5214c73dc..9682fc606465 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/factory/FactoryException.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/factory/FactoryException.java @@ -17,13 +17,16 @@ package org.apache.seatunnel.api.table.factory; -public class FactoryException extends RuntimeException { +import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode; +import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; + +public class FactoryException extends SeaTunnelRuntimeException { public FactoryException(String message, Throwable cause) { - super(message, cause); + super(SeaTunnelAPIErrorCode.FACTORY_INITIALIZATION_FAILED, message, cause); } public FactoryException(String message) { - super(message); + super(SeaTunnelAPIErrorCode.FACTORY_INITIALIZATION_FAILED, message); } }