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

zhaojinchao 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 de78d80d038 Add ShardingSphereException and 
ShardingSphereInsideException in infra-util module (#19981)
de78d80d038 is described below

commit de78d80d038ea71041f33b63065d1f2feb0e4318
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 8 19:53:58 2022 +0800

    Add ShardingSphereException and ShardingSphereInsideException in infra-util 
module (#19981)
---
 .../infra/exception/ShardingSphereException.java     |  9 ---------
 .../ShardingSphereException.java}                    | 16 ++++++++--------
 .../ShardingSphereInsideException.java}              | 20 ++++++++++++--------
 .../props/exception/TypedPropertiesException.java    | 12 ++++++------
 .../props/exception/TypedPropertyValueException.java |  5 +++--
 .../exception/ServiceProviderNotFoundException.java  | 10 +++++++---
 6 files changed, 36 insertions(+), 36 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/ShardingSphereException.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/ShardingSphereException.java
index abae3c6a16e..0c9e952c163 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/ShardingSphereException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/ShardingSphereException.java
@@ -52,13 +52,4 @@ public class ShardingSphereException extends 
RuntimeException {
     public ShardingSphereException(final Exception cause) {
         super(cause);
     }
-    
-    /**
-     * Constructs an exception with error message.
-     *
-     * @param message error message
-     */
-    public ShardingSphereException(final String message) {
-        super(message);
-    }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ShardingSphereSPIException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSphereException.java
similarity index 56%
copy from 
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ShardingSphereSPIException.java
copy to 
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSphereException.java
index 45444857aed..25667a66611 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ShardingSphereSPIException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSphereException.java
@@ -15,20 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.util.spi.exception;
+package org.apache.shardingsphere.infra.util.exception;
 
 /**
- * ShardingSphere SPI exception.
+ * ShardingSphere exception.
  */
-public abstract class ShardingSphereSPIException extends RuntimeException {
+public abstract class ShardingSphereException extends RuntimeException {
     
-    private static final long serialVersionUID = -3044979409127407014L;
+    private static final long serialVersionUID = 1547233217081261239L;
     
-    public ShardingSphereSPIException(final int errorCode, final String 
message) {
-        super(createErrorMessage(errorCode, message));
+    public ShardingSphereException(final String errorCategory, final int 
errorCode, final String message) {
+        super(String.format("%s-%05d: %s", errorCategory, errorCode, message));
     }
     
-    private static String createErrorMessage(final int errorCode, final String 
message) {
-        return String.format("SPI-%05d: %s", errorCode, message);
+    public ShardingSphereException(final String errorCategory, final int 
errorCode, final String message, final Exception cause) {
+        super(String.format("%s-%05d: %s", errorCategory, errorCode, message), 
cause);
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ShardingSphereSPIException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSphereInsideException.java
similarity index 58%
rename from 
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ShardingSphereSPIException.java
rename to 
shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSphereInsideException.java
index 45444857aed..cdc58df4671 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ShardingSphereSPIException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSphereInsideException.java
@@ -15,20 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.util.spi.exception;
+package org.apache.shardingsphere.infra.util.exception;
 
 /**
- * ShardingSphere SPI exception.
+ * ShardingSphere inside exception.
  */
-public abstract class ShardingSphereSPIException extends RuntimeException {
+public abstract class ShardingSphereInsideException extends Exception {
     
-    private static final long serialVersionUID = -3044979409127407014L;
+    private static final long serialVersionUID = -8238061892944243621L;
     
-    public ShardingSphereSPIException(final int errorCode, final String 
message) {
-        super(createErrorMessage(errorCode, message));
+    public ShardingSphereInsideException(final String errorMessage, final 
Object... args) {
+        super(String.format(errorMessage, args));
     }
     
-    private static String createErrorMessage(final int errorCode, final String 
message) {
-        return String.format("SPI-%05d: %s", errorCode, message);
+    public ShardingSphereInsideException(final String message, final Exception 
cause) {
+        super(message, cause);
+    }
+    
+    public ShardingSphereInsideException(final Exception cause) {
+        super(cause);
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
index 1b3bd3d997f..93182b1a019 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertiesException.java
@@ -17,22 +17,22 @@
 
 package org.apache.shardingsphere.infra.util.props.exception;
 
+import org.apache.shardingsphere.infra.util.exception.ShardingSphereException;
+
 import java.util.Collection;
 
 /**
  * Typed properties exception.
  */
-public final class TypedPropertiesException extends RuntimeException {
+public final class TypedPropertiesException extends ShardingSphereException {
     
     private static final long serialVersionUID = -8301410307117564844L;
     
+    private static final String ERROR_CATEGORY = "PROPS";
+    
     private static final int ERROR_CODE = 1;
     
     public TypedPropertiesException(final Collection<String> errorMessages) {
-        super(createErrorMessage(errorMessages));
-    }
-    
-    private static String createErrorMessage(final Collection<String> 
errorMessages) {
-        return String.format("PROPS-%05d: %s", ERROR_CODE, 
String.join(System.lineSeparator(), errorMessages));
+        super(ERROR_CATEGORY, ERROR_CODE, String.join(System.lineSeparator(), 
errorMessages));
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
index 3f8201c56a5..f0eca7c6429 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/props/exception/TypedPropertyValueException.java
@@ -17,16 +17,17 @@
 
 package org.apache.shardingsphere.infra.util.props.exception;
 
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSphereInsideException;
 import org.apache.shardingsphere.infra.util.props.TypedPropertyKey;
 
 /**
  * Typed property value exception.
  */
-public final class TypedPropertyValueException extends Exception {
+public final class TypedPropertyValueException extends 
ShardingSphereInsideException {
     
     private static final long serialVersionUID = -2989212435757964906L;
     
     public TypedPropertyValueException(final TypedPropertyKey key, final 
String value) {
-        super(String.format("Value `%s` of `%s` cannot convert to type `%s`.", 
value, key.getKey(), key.getType().getName()));
+        super("Value `%s` of `%s` cannot convert to type `%s`.", value, 
key.getKey(), key.getType().getName());
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ServiceProviderNotFoundException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ServiceProviderNotFoundException.java
index bccc7ea0272..9ab89ed30a8 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ServiceProviderNotFoundException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/spi/exception/ServiceProviderNotFoundException.java
@@ -17,20 +17,24 @@
 
 package org.apache.shardingsphere.infra.util.spi.exception;
 
+import org.apache.shardingsphere.infra.util.exception.ShardingSphereException;
+
 /**
  * Service provider not found exception.
  */
-public final class ServiceProviderNotFoundException extends 
ShardingSphereSPIException {
+public final class ServiceProviderNotFoundException extends 
ShardingSphereException {
     
     private static final long serialVersionUID = -3730257541332863236L;
     
+    private static final String ERROR_CATEGORY = "SPI";
+    
     private static final int ERROR_CODE = 1;
     
     public ServiceProviderNotFoundException(final Class<?> clazz) {
-        super(ERROR_CODE, String.format("No implementation class load from SPI 
`%s`.", clazz.getName()));
+        super(ERROR_CATEGORY, ERROR_CODE, String.format("No implementation 
class load from SPI `%s`.", clazz.getName()));
     }
     
     public ServiceProviderNotFoundException(final Class<?> clazz, final String 
type) {
-        super(ERROR_CODE, String.format("No implementation class load from SPI 
`%s` with type `%s`.", clazz.getName(), type));
+        super(ERROR_CATEGORY, ERROR_CODE, String.format("No implementation 
class load from SPI `%s` with type `%s`.", clazz.getName(), type));
     }
 }

Reply via email to