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

duanzhengqiang 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 e7e2b07a9f8 Refactor ServerSQLException (#30691)
e7e2b07a9f8 is described below

commit e7e2b07a9f88c5c3d407a49d69894281cee9de2c
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Mar 29 12:41:04 2024 +0800

    Refactor ServerSQLException (#30691)
    
    * Refactor ServerSQLException
    
    * Refactor ServerSQLException
    
    * Refactor ServerSQLException
---
 .../content/user-manual/error-code/sql-error-code.cn.md   |  1 +
 .../content/user-manual/error-code/sql-error-code.en.md   |  1 +
 .../external/sql/type/generic/ServerSQLException.java     |  2 +-
 .../dialect/SQLExceptionTransformEngineTest.java          | 15 ++++++++++++---
 4 files changed, 15 insertions(+), 4 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 b69e962821d..0df8e3049f0 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
@@ -286,3 +286,4 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 0A000     | 30001       | Unsupported SQL operation: %s   |
 | 0A000     | 30002       | Database protocol exception: %s |
 | 0A000     | 30003       | Unsupported command: %s         |
+| 0A000     | 30004       | Server exception: %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 318ad0dc02e..8bb7e033d54 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
@@ -301,3 +301,4 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 0A000     | 30001       | Unsupported SQL operation: %s   |
 | 0A000     | 30002       | Database protocol exception: %s |
 | 0A000     | 30003       | Unsupported command: %s         |
+| 0A000     | 30004       | Server exception: %s            |
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
index 3ffe3a108d3..2ba898650c2 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
@@ -27,6 +27,6 @@ public final class ServerSQLException extends 
GenericSQLException {
     private static final long serialVersionUID = -4072647406344887711L;
     
     public ServerSQLException(final Exception cause) {
-        super(cause.getMessage(), cause, XOpenSQLState.GENERAL_ERROR, 0);
+        super(String.format("Server exception: %s", cause.getMessage()), 
cause, XOpenSQLState.GENERAL_ERROR, 4);
     }
 }
diff --git 
a/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
 
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
index 841379c7f42..86209afa77f 100644
--- 
a/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
+++ 
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
@@ -54,7 +54,10 @@ class SQLExceptionTransformEngineTest {
     void assertToSQLExceptionWithDatabaseProtocolException() {
         DatabaseProtocolException cause = 
mock(DatabaseProtocolException.class);
         when(cause.getMessage()).thenReturn("No reason");
-        assertThat(SQLExceptionTransformEngine.toSQLException(cause, 
databaseType).getMessage(), is("Database protocol exception: No reason"));
+        SQLException actual = 
SQLExceptionTransformEngine.toSQLException(cause, databaseType);
+        assertThat(actual.getSQLState(), is("HY000"));
+        assertThat(actual.getErrorCode(), is(30002));
+        assertThat(actual.getMessage(), is("Database protocol exception: No 
reason"));
     }
     
     @Test
@@ -66,11 +69,17 @@ class SQLExceptionTransformEngineTest {
     void assertToSQLExceptionWithShardingSphereServerException() {
         ShardingSphereServerException cause = 
mock(ShardingSphereServerException.class);
         when(cause.getMessage()).thenReturn("No reason");
-        assertThat(SQLExceptionTransformEngine.toSQLException(cause, 
databaseType).getMessage(), is("No reason"));
+        SQLException actual = 
SQLExceptionTransformEngine.toSQLException(cause, databaseType);
+        assertThat(actual.getSQLState(), is("HY000"));
+        assertThat(actual.getErrorCode(), is(30004));
+        assertThat(actual.getMessage(), is("Server exception: No reason"));
     }
     
     @Test
     void assertToSQLExceptionWithOtherException() {
-        assertThat(SQLExceptionTransformEngine.toSQLException(new 
Exception("No reason"), databaseType).getMessage(), is("Unknown exception: No 
reason"));
+        SQLException actual = SQLExceptionTransformEngine.toSQLException(new 
Exception("No reason"), databaseType);
+        assertThat(actual.getSQLState(), is("HY000"));
+        assertThat(actual.getErrorCode(), is(30000));
+        assertThat(actual.getMessage(), is("Unknown exception: No reason"));
     }
 }

Reply via email to