[branch-2.1][improvement](jdbc catalog) Print more errors when Jdbc Catalog fails to obtain a connection on FE (#41769)

This commit is contained in:
zy-kkk
2024-10-12 21:21:54 +08:00
committed by GitHub
parent e10458baad
commit 68ae6d025e
2 changed files with 18 additions and 2 deletions

View File

@ -175,8 +175,9 @@ public abstract class JdbcClient {
Thread.currentThread().setContextClassLoader(this.classLoader);
conn = dataSource.getConnection();
} catch (Exception e) {
String errorMessage = String.format("Can not connect to jdbc due to error: %s, Catalog name: %s",
e.getMessage(), this.getCatalogName());
String errorMessage = String.format(
"Catalog `%s` can not connect to jdbc due to error: %s",
this.getCatalogName(), JdbcClientException.getAllExceptionMessages(e));
throw new JdbcClientException(errorMessage, e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);

View File

@ -48,4 +48,19 @@ public class JdbcClientException extends RuntimeException {
}
return escapedArgs;
}
public static String getAllExceptionMessages(Throwable throwable) {
StringBuilder sb = new StringBuilder();
while (throwable != null) {
String message = throwable.getMessage();
if (message != null && !message.isEmpty()) {
if (sb.length() > 0) {
sb.append(" | Caused by: ");
}
sb.append(message);
}
throwable = throwable.getCause();
}
return sb.toString();
}
}