Skip to content

Commit

Permalink
[Improve][Core][Api] Unified exceptions and add error code tips in ap…
Browse files Browse the repository at this point in the history
…i module
  • Loading branch information
TyrantLucifer committed Nov 7, 2022
1 parent bcc4b0a commit ae89b3f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@

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);
}

/**
* @param message the detail message.
* @param cause the cause.
*/
public CatalogException(String message, Throwable cause) {
super(message, cause);
super(SeaTunnelAPIErrorCode.CATALOG_ERROR, message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ae89b3f

Please sign in to comment.