Skip to content

Commit 7734a9b

Browse files
committed
chore(chat2mysql): Improve exception handling and logging
1 parent 3e5e6f5 commit 7734a9b

File tree

1 file changed

+11
-2
lines changed
  • mcp-server-chat2mysql/chat2mysql-commons/src/main/java/com/github/mcp/server/chat2mysql/util

1 file changed

+11
-2
lines changed

mcp-server-chat2mysql/chat2mysql-commons/src/main/java/com/github/mcp/server/chat2mysql/util/SqlHelper.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static String showCreateTable(String tableName) {
5555
}
5656
} catch (SQLException e) {
5757
logger.error("Error connecting to MySQL database with jdbc url {}", JDBC_URL, e);
58-
return null;
58+
return formatExceptionStackTrace(e);
5959
}
6060
}
6161

@@ -78,8 +78,17 @@ public static String explainSql(String sql) {
7878
}
7979
} catch (SQLException e) {
8080
logger.error("Error connecting to MySQL database with jdbc url {}", JDBC_URL, e);
81-
return null;
81+
return formatExceptionStackTrace(e);
8282
}
8383
}
8484

85+
private static String formatExceptionStackTrace(Throwable throwable) {
86+
StackTraceElement[] stackTrace = throwable.getStackTrace();
87+
StringBuilder result = new StringBuilder(stackTrace[0] + ": " + throwable.getMessage());
88+
for (int i = 1; i < stackTrace.length; i++) {
89+
result.append("\n\tat ").append(stackTrace[i]);
90+
}
91+
return result.toString();
92+
}
93+
8594
}

0 commit comments

Comments
 (0)