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

sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new b07c996a267 Add ShardingPluginException (#21311)
b07c996a267 is described below

commit b07c996a2670fd2fa5240cd5537075c92652300e
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Oct 2 10:56:11 2022 +0800

    Add ShardingPluginException (#21311)
    
    * Add ShardingPluginException
    
    * Add ShardingPluginException
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../exception/ShardingPluginException.java         | 35 ++++++++++++++++++++++
 .../interval/CosIdIntervalShardingAlgorithm.java   |  9 +++---
 .../CosIdSnowflakeIntervalShardingAlgorithm.java   |  4 +--
 5 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md 
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 490bcb2a30b..10d3b044653 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -174,6 +174,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 20081       | Routed target \`%s\` does not exist, available 
targets are \`%s\`. |
 | 44000     | 20082       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` do not match. |
 | 44000     | 20090       | Can not find strategy for generate keys with table 
\`%s\`. |
+| HY000     | 20099       | Sharding plugin error, reason is: %s |
 
 ### 读写分离
 
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md 
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index d8ecf684547..f55fdc05126 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -174,6 +174,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | HY000     | 20081       | Routed target \`%s\` does not exist, available 
targets are \`%s\`. |
 | 44000     | 20082       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` do not match. |
 | 44000     | 20090       | Can not find strategy for generate keys with table 
\`%s\`. |
+| HY000     | 20099       | Sharding plugin error, reason is: %s |
 
 ### Readwrite Splitting
 
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/exception/ShardingPluginException.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/exception/ShardingPluginException.java
new file mode 100644
index 00000000000..644b61d9d3d
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/exception/ShardingPluginException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.shardingsphere.sharding.exception;
+
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.FeatureSQLException;
+
+/**
+ * Sharding plugin exception.
+ */
+public final class ShardingPluginException extends FeatureSQLException {
+    
+    private static final long serialVersionUID = 3683604626004382449L;
+    
+    private static final int FEATURE_CODE = 0;
+    
+    public ShardingPluginException(final String reason, final Object... 
arguments) {
+        super(XOpenSQLState.GENERAL_ERROR, FEATURE_CODE, 99, "Sharding plugin 
error, reason is: " + reason, arguments);
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
index e33585e48b0..7c4d060d6cf 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval;
 
-import com.google.common.base.Strings;
+import me.ahoo.cosid.util.LocalDateTimeConvert;
+import 
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
+import org.apache.shardingsphere.sharding.exception.ShardingPluginException;
 
 import java.time.Instant;
 import java.time.LocalDate;
@@ -31,9 +33,6 @@ import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.Properties;
 
-import me.ahoo.cosid.util.LocalDateTimeConvert;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
-
 /**
  * Interval range sharding algorithm with CosId.
  */
@@ -98,7 +97,7 @@ public final class CosIdIntervalShardingAlgorithm extends 
AbstractCosIdIntervalS
         if (shardingValue instanceof String) {
             return LocalDateTimeConvert.fromString((String) shardingValue, 
dateTimeFormatter);
         }
-        throw new IllegalArgumentException(Strings.lenientFormat("The current 
shard type:[%s] is not supported!", shardingValue.getClass()));
+        throw new ShardingPluginException("Unsupported sharding value type 
`%s`.", shardingValue);
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
index 062f1d75571..e5d6d3e11c0 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval;
 
-import com.google.common.base.Strings;
 import me.ahoo.cosid.converter.Radix62IdConverter;
 import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
 import me.ahoo.cosid.snowflake.MillisecondSnowflakeIdStateParser;
 import me.ahoo.cosid.snowflake.SnowflakeIdStateParser;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.keygen.CosIdSnowflakeKeyGenerateAlgorithm;
+import org.apache.shardingsphere.sharding.exception.ShardingPluginException;
 
 import java.time.LocalDateTime;
 import java.util.Properties;
@@ -63,7 +63,7 @@ public final class CosIdSnowflakeIntervalShardingAlgorithm 
extends AbstractCosId
             String shardingValueStr = (String) shardingValue;
             return Radix62IdConverter.PAD_START.asLong(shardingValueStr);
         }
-        throw new IllegalArgumentException(Strings.lenientFormat("The current 
shard type:[%s] is not supported!", shardingValue.getClass()));
+        throw new ShardingPluginException("Unsupported sharding value type 
`%s`.", shardingValue);
     }
     
     @Override

Reply via email to