You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/09/24 06:05:38 UTC

[shardingsphere] branch master updated: Reduce `unknownException` throws (#12638)

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

panjuan 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 ab82264  Reduce `unknownException` throws (#12638)
ab82264 is described below

commit ab822644afa88c32ebe6ba3edd123a924e2a21e6
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Fri Sep 24 01:05:01 2021 -0500

    Reduce `unknownException` throws (#12638)
    
    * Handle `runtime exception` and prevent `unknown Exception` from being thrown
    
    * Adjust test.
---
 .../shardingsphere/db/protocol/error/CommonErrorCode.java     |  2 ++
 .../proxy/frontend/mysql/err/MySQLErrPacketFactory.java       |  3 +++
 .../proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java   | 11 ++++++++++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
index 489e0ec..5f97e4a 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
@@ -37,6 +37,8 @@ public enum CommonErrorCode implements SQLErrorCode {
     
     TABLE_LOCKED(1302, "C1302", "The table %s of schema %s is locked"),
     
+    RUNTIME_EXCEPTION(1997, "C1997", "Runtime exception: [%s]"),
+    
     UNSUPPORTED_COMMAND(1998, "C1998", "Unsupported command: [%s]"),
     
     UNKNOWN_EXCEPTION(1999, "C1999", "Unknown exception: [%s]");
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index a31a176..dc48c7b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -116,6 +116,9 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof ScalingJobNotFoundException) {
             return new MySQLErrPacket(1, CommonErrorCode.SCALING_JOB_NOT_EXIST, ((ScalingJobNotFoundException) cause).getJobId());
         }
+        if (cause instanceof RuntimeException) {
+            return new MySQLErrPacket(1, CommonErrorCode.RUNTIME_EXCEPTION, cause.getMessage());
+        }
         return new MySQLErrPacket(1, CommonErrorCode.UNKNOWN_EXCEPTION, cause.getMessage());
     }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 04d0286..012d5fe 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -206,10 +206,19 @@ public final class MySQLErrPacketFactoryTest {
     
     @Test
     public void assertNewInstanceWithOtherException() {
-        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new RuntimeException("No reason"));
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new ReflectiveOperationException("No reason"));
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(1999));
         assertThat(actual.getSqlState(), is("C1999"));
         assertThat(actual.getErrorMessage(), is("Unknown exception: [No reason]"));
     }
+    
+    @Test
+    public void assertNewInstanceWithRuntimeException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new RuntimeException("No reason"));
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(1997));
+        assertThat(actual.getSqlState(), is("C1997"));
+        assertThat(actual.getErrorMessage(), is("Runtime exception: [No reason]"));
+    }
 }