This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 721c0caeb70 Refactor ShardingSphereSQLException (#30761)
721c0caeb70 is described below
commit 721c0caeb7000d5648ef2b8e1fd7a8a75f400b17
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 3 23:41:32 2024 +0800
Refactor ShardingSphereSQLException (#30761)
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
* Refactor ShardingSphereSQLException
---
.../exception/core/external/sql/ShardingSphereSQLException.java | 5 ++++-
.../core/external/sql/type/generic/UnknownSQLException.java | 2 +-
.../core/external/sql/type/wrapper/SQLWrapperException.java | 2 +-
.../core/external/sql/type/generic/UnknownSQLExceptionTest.java | 2 +-
.../core/external/sql/type/kernel/KernelSQLExceptionTest.java | 2 +-
.../core/external/sql/type/wrapper/SQLWrapperExceptionTest.java | 2 +-
.../infra/exception/dialect/SQLExceptionTransformEngineTest.java | 4 ++--
.../proxy/frontend/mysql/err/MySQLErrorPacketFactoryTest.java | 2 +-
.../frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java | 2 +-
.../frontend/postgresql/err/PostgreSQLErrorPacketFactoryTest.java | 2 +-
10 files changed, 14 insertions(+), 11 deletions(-)
diff --git
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
index 758c7323f50..51a47445c56 100644
---
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
+++
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.exception.core.external.sql;
import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
import
org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.SQLState;
@@ -52,7 +53,9 @@ public abstract class ShardingSphereSQLException extends
ShardingSphereExternalE
Preconditions.checkArgument(typeOffset >= 0 && typeOffset < 4, "The
value range of type offset should be [0, 3].");
Preconditions.checkArgument(errorCode >= 0 && errorCode < 10000, "The
value range of error code should be [0, 10000).");
vendorCode = typeOffset * 10000 + errorCode;
- this.reason = reason;
+ this.reason = null == cause ||
Strings.isNullOrEmpty(cause.getMessage())
+ ? reason
+ : String.format("%s%sMore details: %s", reason,
System.lineSeparator(), cause.getMessage());
this.cause = cause;
}
diff --git
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLException.java
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLException.java
index 5227219e742..f538f64a91a 100644
---
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLException.java
+++
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLException.java
@@ -27,6 +27,6 @@ public final class UnknownSQLException extends
GenericSQLException {
private static final long serialVersionUID = -7357918573504734977L;
public UnknownSQLException(final Exception cause) {
- super(String.format("Unknown exception: %s", cause.getMessage()),
cause, XOpenSQLState.GENERAL_ERROR, 0);
+ super("Unknown exception.", cause, XOpenSQLState.GENERAL_ERROR, 0);
}
}
diff --git
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java
index 5d3acd3dcc7..5b1ef7f6e5f 100644
---
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java
+++
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java
@@ -31,6 +31,6 @@ public final class SQLWrapperException extends
ShardingSphereSQLException {
private static final int TYPE_OFFSET = 0;
public SQLWrapperException(final SQLException cause) {
- super(cause.getSQLState(), TYPE_OFFSET, cause.getErrorCode(),
cause.getMessage(), cause);
+ super(cause.getSQLState(), TYPE_OFFSET, cause.getErrorCode(), "",
cause);
}
}
diff --git
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLExceptionTest.java
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLExceptionTest.java
index ff301bc0712..538ec9b868d 100644
---
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLExceptionTest.java
+++
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/UnknownSQLExceptionTest.java
@@ -32,6 +32,6 @@ class UnknownSQLExceptionTest {
SQLException actual = new UnknownSQLException(new
RuntimeException("foo_reason")).toSQLException();
assertThat(actual.getSQLState(),
is(XOpenSQLState.GENERAL_ERROR.getValue()));
assertThat(actual.getErrorCode(), is(30000));
- assertThat(actual.getMessage(), is("Unknown exception: foo_reason"));
+ assertThat(actual.getMessage(), is("Unknown exception." +
System.lineSeparator() + "More details: foo_reason"));
}
}
diff --git
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
index 0f2d36eb621..4dd577e91f2 100644
---
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
+++
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
@@ -45,7 +45,7 @@ class KernelSQLExceptionTest {
}.toSQLException();
assertThat(actual.getSQLState(),
is(XOpenSQLState.GENERAL_ERROR.getValue()));
assertThat(actual.getErrorCode(), is(11001));
- assertThat(actual.getMessage(), is("reason"));
+ assertThat(actual.getMessage(), is("reason" + System.lineSeparator() +
"More details: test"));
assertThat(actual.getCause(), is(cause));
}
}
diff --git
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java
index 58a15ec6e33..c3ed9e32344 100644
---
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java
+++
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java
@@ -31,6 +31,6 @@ class SQLWrapperExceptionTest {
SQLException actual = new SQLWrapperException(new
SQLException("reason", "1", 10)).toSQLException();
assertThat(actual.getSQLState(), is("1"));
assertThat(actual.getErrorCode(), is(10));
- assertThat(actual.getMessage(), is("reason"));
+ assertThat(actual.getMessage(), is(System.lineSeparator() + "More
details: reason"));
}
}
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 86209afa77f..bd2df85ef15 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
@@ -72,7 +72,7 @@ class SQLExceptionTransformEngineTest {
SQLException actual =
SQLExceptionTransformEngine.toSQLException(cause, databaseType);
assertThat(actual.getSQLState(), is("HY000"));
assertThat(actual.getErrorCode(), is(30004));
- assertThat(actual.getMessage(), is("Server exception: No reason"));
+ assertThat(actual.getMessage(), is("Server exception: No reason" +
System.lineSeparator() + "More details: No reason"));
}
@Test
@@ -80,6 +80,6 @@ class SQLExceptionTransformEngineTest {
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"));
+ assertThat(actual.getMessage(), is("Unknown exception." +
System.lineSeparator() + "More details: No reason"));
}
}
diff --git
a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrorPacketFactoryTest.java
b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrorPacketFactoryTest.java
index 847522da441..9a5d0b45887 100644
---
a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrorPacketFactoryTest.java
+++
b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrorPacketFactoryTest.java
@@ -41,6 +41,6 @@ class MySQLErrorPacketFactoryTest {
MySQLErrPacket actual = MySQLErrorPacketFactory.newInstance(new
RuntimeException("No reason"));
assertThat(actual.getErrorCode(), is(30000));
assertThat(actual.getSqlState(),
is(XOpenSQLState.GENERAL_ERROR.getValue()));
- assertThat(actual.getErrorMessage(), is("Unknown exception: No
reason"));
+ assertThat(actual.getErrorMessage(), is("Unknown exception." +
System.lineSeparator() + "More details: No reason"));
}
}
diff --git
a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
index 689be82bc5e..5903aa02a77 100644
---
a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
+++
b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
@@ -74,7 +74,7 @@ class OpenGaussErrorPacketFactoryTest {
assertThat(actualFields.size(), is(4));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_SEVERITY),
is("ERROR"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_CODE),
is("58000"));
-
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("Unknown exception: No reason"));
+
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("Unknown exception." + System.lineSeparator() + "More details: No reason"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERRORCODE),
is("0"));
}
diff --git
a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrorPacketFactoryTest.java
b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrorPacketFactoryTest.java
index b6cc9aba9a1..61530804985 100644
---
a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrorPacketFactoryTest.java
+++
b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrorPacketFactoryTest.java
@@ -62,6 +62,6 @@ class PostgreSQLErrorPacketFactoryTest {
void assertRuntimeException() throws ReflectiveOperationException {
PostgreSQLErrorResponsePacket actual =
PostgreSQLErrorPacketFactory.newInstance(new RuntimeException("No reason"));
Map<Character, String> fields = (Map<Character, String>)
Plugins.getMemberAccessor().get(PostgreSQLErrorResponsePacket.class.getDeclaredField("fields"),
actual);
-
assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("Unknown exception: No reason"));
+
assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("Unknown exception." + System.lineSeparator() + "More details: No reason"));
}
}