geyanggang commented on code in PR #13769:
URL: https://github.com/apache/gravitino/pull/13769#discussion_r4246675287


##########
catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/JdbcCatalogOperations.java:
##########
@@ -248,12 +248,54 @@ public void testConnection(NameIdentifier catalogIdent) {
     } catch (GravitinoRuntimeException e) {
       if (e.getClass() == GravitinoRuntimeException.class && e.getCause() 
instanceof SQLException) {
         throw new ConnectionFailedException(
-            e.getCause(), "Failed to connect to JDBC catalog: %s", 
e.getMessage());
+            e.getCause(),
+            "Failed to connect to JDBC catalog at %s: %s",
+            hostPortFromJdbcUrl(jdbcUrl),
+            e.getMessage());
       }
       throw e;
     }
   }
 
+  /**
+   * Extracts {@code host:port} from a {@code 
jdbc:subprotocol://host:port/...} URL for use in a
+   * connection-failure message. Returns the raw URL when the host/port cannot 
be located and {@code
+   * "unknown"} when the URL is blank. Never throws, so message formatting 
cannot mask the original
+   * connection failure.
+   *
+   * @param url the JDBC URL stored for this catalog
+   * @return a {@code host:port} description, the raw URL, or {@code "unknown"}
+   */
+  private static String hostPortFromJdbcUrl(String url) {
+    if (StringUtils.isBlank(url)) {
+      return "unknown";
+    }
+    int schemeEnd = url.indexOf("://");
+    if (schemeEnd < 0) {
+      return url;

Review Comment:
   Fixed. hostPortFromJdbcUrl returns "unknown" on every fallback, so a 
credential-bearing URL (e.g. jdbc:postgresql:db?password=...) can no longer 
leak into the exception, REST response, or logs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to