[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:
@ -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);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user