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

singhpk234 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 8f488d5bc JDBC: Include error code + SQL state in exception messages 
(#2220)
8f488d5bc is described below

commit 8f488d5bc202d699f46cd99c1b1d43520439972e
Author: Robert Stupp <sn...@snazy.de>
AuthorDate: Thu Jul 31 23:19:41 2025 +0200

    JDBC: Include error code + SQL state in exception messages (#2220)
---
 .../polaris/persistence/relational/jdbc/DatasourceOperations.java | 8 ++++++--
 .../persistence/relational/jdbc/DatasourceOperationsTest.java     | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git 
a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
 
b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
index 8dd994869..f5afbc04d 100644
--- 
a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
+++ 
b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
@@ -286,8 +286,12 @@ public class DatasourceOperations {
         if (timeLeft == 0 || attempts >= maxAttempts || 
!isRetryable(sqlException)) {
           String exceptionMessage =
               String.format(
-                  "Failed due to %s, after , %s attempts and %s milliseconds",
-                  sqlException.getMessage(), attempts, maxDuration);
+                  "Failed due to '%s' (error code %d, sql-state '%s'), after 
%s attempts and %s milliseconds",
+                  sqlException.getMessage(),
+                  sqlException.getErrorCode(),
+                  sqlException.getSQLState(),
+                  attempts,
+                  maxDuration);
           throw new SQLException(
               exceptionMessage, sqlException.getSQLState(), 
sqlException.getErrorCode(), e);
         }
diff --git 
a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperationsTest.java
 
b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperationsTest.java
index ae6f569cc..26f452a08 100644
--- 
a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperationsTest.java
+++ 
b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperationsTest.java
@@ -182,7 +182,7 @@ public class DatasourceOperationsTest {
     SQLException thrown =
         assertThrows(SQLException.class, () -> 
datasourceOperations.withRetries(mockOperation));
     assertEquals(
-        "Failed due to Retryable error, after , 2 attempts and 1000 
milliseconds",
+        "Failed due to 'Retryable error' (error code 0, sql-state '40001'), 
after 2 attempts and 1000 milliseconds",
         thrown.getMessage());
     verify(mockOperation, times(2)).execute(); // Tried twice, then threw
   }
@@ -213,7 +213,7 @@ public class DatasourceOperationsTest {
     SQLException thrown =
         assertThrows(SQLException.class, () -> 
datasourceOperations.withRetries(mockOperation));
     assertEquals(
-        "Failed due to NonRetryable error, after , 1 attempts and 1000 
milliseconds",
+        "Failed due to 'NonRetryable error' (error code 0, sql-state 'null'), 
after 1 attempts and 1000 milliseconds",
         thrown.getMessage());
     verify(mockOperation, times(1)).execute(); // Should not retry
   }

Reply via email to