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

terrymanu 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 071c4533d56 Clarify literal message handling for pipeline SQL 
exceptions (#40325)
071c4533d56 is described below

commit 071c4533d566bd1ce96457cf7ad2003ddf27d78d
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Oct 22 12:10:14 2026 +0800

    Clarify literal message handling for pipeline SQL exceptions (#40325)
---
 .../sql/type/kernel/KernelSQLException.java        | 13 +++++++
 .../type/kernel/category/PipelineSQLException.java |  4 +-
 .../sql/type/kernel/KernelSQLExceptionTest.java    | 43 ++++++++++++++++++++++
 .../PipelineSQLExceptionTest.java}                 | 32 +++++++++-------
 4 files changed, 76 insertions(+), 16 deletions(-)

diff --git 
a/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLException.java
 
b/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLException.java
index 2bf59d26655..33f84305f28 100644
--- 
a/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLException.java
+++ 
b/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLException.java
@@ -38,6 +38,19 @@ public abstract class KernelSQLException extends 
ShardingSphereSQLException {
         super(sqlState, TYPE_OFFSET, getErrorCode(kernelCode, errorCode), 
cause, reason, messageArgs);
     }
     
+    /**
+     * Create a kernel SQL exception without formatting the reason.
+     *
+     * @param reason literal exception message
+     * @param sqlState SQL state
+     * @param kernelCode kernel code
+     * @param errorCode error code
+     * @param cause cause, or {@code null} if absent
+     */
+    protected KernelSQLException(final String reason, final SQLState sqlState, 
final int kernelCode, final int errorCode, final Exception cause) {
+        super(sqlState.getValue(), TYPE_OFFSET, getErrorCode(kernelCode, 
errorCode), reason, cause);
+    }
+    
     private static int getErrorCode(final int kernelCode, final int errorCode) 
{
         Preconditions.checkArgument(kernelCode >= 0 && kernelCode < 10, "The 
value range of kernel code should be [0, 10).");
         Preconditions.checkArgument(errorCode >= 0 && errorCode < 1000, "The 
value range of error code should be [0, 1000).");
diff --git 
a/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLException.java
 
b/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLException.java
index 407c4199be2..2f45b05bbaf 100644
--- 
a/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLException.java
+++ 
b/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLException.java
@@ -30,10 +30,10 @@ public abstract class PipelineSQLException extends 
KernelSQLException {
     private static final int KERNEL_CODE = 8;
     
     protected PipelineSQLException(final SQLState sqlState, final int 
errorCode, final String reason) {
-        super(sqlState, KERNEL_CODE, errorCode, reason);
+        super(reason, sqlState, KERNEL_CODE, errorCode, null);
     }
     
     protected PipelineSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, KERNEL_CODE, errorCode, cause, reason);
+        super(reason, sqlState, KERNEL_CODE, errorCode, cause);
     }
 }
diff --git 
a/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
 
b/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
index 47a1533fe7f..af1d38b89ba 100644
--- 
a/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
+++ 
b/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
@@ -19,11 +19,14 @@ package 
org.apache.shardingsphere.infra.exception.external.sql.type.kernel;
 
 import 
org.apache.shardingsphere.infra.exception.external.sql.sqlstate.XOpenSQLState;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import java.sql.SQLException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
 class KernelSQLExceptionTest {
@@ -48,4 +51,44 @@ class KernelSQLExceptionTest {
         assertThat(actual.getMessage(), is("reason" + System.lineSeparator() + 
"More details: java.lang.RuntimeException: test"));
         assertThat(actual.getCause(), is(cause));
     }
+    
+    @ParameterizedTest(name = "{index}: literal reason={0}")
+    @ValueSource(strings = {"foo_reason", "foo_%s_%1$s_%n_%%_%", ""})
+    void assertToSQLExceptionWithLiteralReason(final String reason) {
+        SQLException actual = new KernelSQLException(reason, 
XOpenSQLState.GENERAL_ERROR, 1, 1, null) {
+        }.toSQLException();
+        assertThat(actual.getSQLState(), 
is(XOpenSQLState.GENERAL_ERROR.getValue()));
+        assertThat(actual.getErrorCode(), is(11001));
+        assertThat(actual.getMessage(), is(reason));
+        assertNull(actual.getCause());
+    }
+    
+    @Test
+    void assertToSQLExceptionWithLiteralReasonAndCause() {
+        Exception cause = new RuntimeException("foo_cause_%s");
+        SQLException actual = new KernelSQLException("foo_%s_%n_%%_%", 
XOpenSQLState.GENERAL_ERROR, 1, 1, cause) {
+        }.toSQLException();
+        assertThat(actual.getSQLState(), 
is(XOpenSQLState.GENERAL_ERROR.getValue()));
+        assertThat(actual.getErrorCode(), is(11001));
+        assertThat(actual.getMessage(), is("foo_%s_%n_%%_%" + 
System.lineSeparator() + "More details: java.lang.RuntimeException: 
foo_cause_%s"));
+        assertThat(actual.getCause(), sameInstance(cause));
+    }
+    
+    @Test
+    void assertToSQLExceptionWithExceptionMessageArgument() {
+        Exception messageArg = new RuntimeException("foo_argument");
+        SQLException actual = new 
KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "foo_%s", messageArg) {
+        }.toSQLException();
+        assertThat(actual.getMessage(), is("foo_java.lang.RuntimeException: 
foo_argument"));
+        assertNull(actual.getCause());
+    }
+    
+    @Test
+    void assertToSQLExceptionWithCauseAndMessageArguments() {
+        Exception cause = new RuntimeException("foo_cause");
+        SQLException actual = new 
KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, cause, "foo_%s_%d", 
"bar_value", 2) {
+        }.toSQLException();
+        assertThat(actual.getMessage(), is("foo_bar_value_2" + 
System.lineSeparator() + "More details: java.lang.RuntimeException: 
foo_cause"));
+        assertThat(actual.getCause(), sameInstance(cause));
+    }
 }
diff --git 
a/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
 
b/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLExceptionTest.java
similarity index 51%
copy from 
infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
copy to 
infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLExceptionTest.java
index 47a1533fe7f..40796e90781 100644
--- 
a/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
+++ 
b/infra/exception/src/test/java/org/apache/shardingsphere/infra/exception/external/sql/type/kernel/category/PipelineSQLExceptionTest.java
@@ -15,37 +15,41 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.exception.external.sql.type.kernel;
+package 
org.apache.shardingsphere.infra.exception.external.sql.type.kernel.category;
 
 import 
org.apache.shardingsphere.infra.exception.external.sql.sqlstate.XOpenSQLState;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import java.sql.SQLException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
-class KernelSQLExceptionTest {
+class PipelineSQLExceptionTest {
     
-    @Test
-    void assertToSQLException() {
-        SQLException actual = new 
KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "reason") {
+    @ParameterizedTest(name = "{index}: literal reason={0}")
+    @ValueSource(strings = {"foo_reason", "foo_%s_%1$s_%n_%%_%", ""})
+    void assertToSQLException(final String reason) {
+        SQLException actual = new 
PipelineSQLException(XOpenSQLState.INVALID_PARAMETER_VALUE, 0, reason) {
         }.toSQLException();
-        assertThat(actual.getSQLState(), 
is(XOpenSQLState.GENERAL_ERROR.getValue()));
-        assertThat(actual.getErrorCode(), is(11001));
-        assertThat(actual.getMessage(), is("reason"));
+        assertThat(actual.getSQLState(), 
is(XOpenSQLState.INVALID_PARAMETER_VALUE.getValue()));
+        assertThat(actual.getErrorCode(), is(18000));
+        assertThat(actual.getMessage(), is(reason));
         assertNull(actual.getCause());
     }
     
     @Test
     void assertToSQLExceptionWithCause() {
-        Exception cause = new RuntimeException("test");
-        SQLException actual = new 
KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, cause, "reason") {
+        Exception cause = new RuntimeException("foo_cause_%s");
+        SQLException actual = new 
PipelineSQLException(XOpenSQLState.INVALID_PARAMETER_VALUE, 0, 
"foo_%s_%n_%%_%", cause) {
         }.toSQLException();
-        assertThat(actual.getSQLState(), 
is(XOpenSQLState.GENERAL_ERROR.getValue()));
-        assertThat(actual.getErrorCode(), is(11001));
-        assertThat(actual.getMessage(), is("reason" + System.lineSeparator() + 
"More details: java.lang.RuntimeException: test"));
-        assertThat(actual.getCause(), is(cause));
+        assertThat(actual.getSQLState(), 
is(XOpenSQLState.INVALID_PARAMETER_VALUE.getValue()));
+        assertThat(actual.getErrorCode(), is(18000));
+        assertThat(actual.getMessage(), is("foo_%s_%n_%%_%" + 
System.lineSeparator() + "More details: java.lang.RuntimeException: 
foo_cause_%s"));
+        assertThat(actual.getCause(), sameInstance(cause));
     }
 }

Reply via email to