fix(jdbc): 为缺少依赖的自定义驱动提供安装入口

This commit is contained in:
zipg authored and GitHub committed 2026-07-20 11:34:23 +08:00
1 parent 1e76d60f16
commit e4aa0d3956
10 files changed
+68 -6

No files matched your search

@@ -17,7 +17,25 @@ function mysqlConfig(urlParams: string | undefined): ConnectionConfig {
};
}
const t = (key: string) => (key === "connection.mysqlTlsConnectionFailureHint" ? "Set TLS Mode to Disabled." : key);
function jdbcConfig(): ConnectionConfig {
return {
id: "jdbc-test",
name: "TDengine JDBC",
db_type: "jdbc",
host: "127.0.0.1",
port: 6041,
username: "root",
password: "",
database: "dbx_tdengine_demo",
ssl: false,
};
}
const t = (key: string) => {
if (key === "connection.mysqlTlsConnectionFailureHint") return "Set TLS Mode to Disabled.";
if (key === "connection.jdbcMissingRuntimeDependencyHint") return "Install from Maven or import every dependency JAR.";
return key;
};
describe("appendConnectionErrorHints", () => {
it("adds a MySQL TLS hint for non-disabled TLS failures", () => {
@@ -45,4 +63,18 @@ describe("appendConnectionErrorHints", () => {
expect(message).toBe("Access denied for user root");
});
it("adds an installation hint when a custom JDBC driver is missing a runtime dependency", () => {
const error = "Missing Java class com.alibaba.fastjson.JSONException. Install the required runtime dependency.";
const message = appendConnectionErrorHints(jdbcConfig(), error, t);
expect(message).toContain(error);
expect(message).toContain("Install from Maven or import every dependency JAR.");
});
it("does not add the JDBC dependency hint to non-JDBC connections", () => {
const error = "Missing Java class com.alibaba.fastjson.JSONException. Install the required runtime dependency.";
expect(appendConnectionErrorHints(mysqlConfig(undefined), error, t)).toBe(error);
});
});
@@ -37,10 +37,23 @@ function isMysqlTlsLikeFailure(message: string): boolean {
);
}
export function isJdbcMissingRuntimeDependencyError(message: string): boolean {
return /Missing Java class|NoClassDefFoundError|ClassNotFoundException/i.test(message);
}
function appendHint(message: string, hint: string): string {
return message.includes(hint) ? message : `${message}\n\n${hint}`;
}
export function appendConnectionErrorHints(config: ConnectionConfig | undefined, message: string, t: Translate): string {
if (!config || config.db_type !== "mysql") return message;
if (!config) return message;
let result = message;
if (config.db_type === "jdbc" && isJdbcMissingRuntimeDependencyError(message)) {
result = appendHint(result, t("connection.jdbcMissingRuntimeDependencyHint"));
}
if (config.db_type !== "mysql") return result;
if (mysqlTlsMode(config) === "disabled") return message;
if (!isMysqlTlsLikeFailure(message)) return message;
const hint = t("connection.mysqlTlsConnectionFailureHint");
return message.includes(hint) ? message : `${message}\n\n${hint}`;
return appendHint(message, hint);
}