Skip to content

Commit 3aea646

Browse files
committed
improve: Improved the org.springframework.ai.model.tool.autoconfigure.ToolCallingAutoConfiguration#getClassOrNull method to only log the name of the class that failed to load, instead of printing the full stack trace when a ClassNotFoundException occurs.
Signed-off-by: Sun Yuhan <[email protected]>
1 parent 6880753 commit 3aea646

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

auto-configurations/models/tool/spring-ai-autoconfigure-model-tool/src/main/java/org/springframework/ai/model/tool/autoconfigure/ToolCallingAutoConfiguration.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,19 @@ ToolCallingContentObservationFilter toolCallingContentObservationFilter() {
126126

127127
private static Class<? extends RuntimeException> getClassOrNull(String className) {
128128
try {
129-
return (Class<? extends RuntimeException>) ClassUtils.forName(className, null);
129+
Class<?> clazz = ClassUtils.forName(className, null);
130+
if (RuntimeException.class.isAssignableFrom(clazz)) {
131+
return (Class<? extends RuntimeException>) clazz;
132+
}
133+
else {
134+
logger.debug("Class {} is not a subclass of RuntimeException", className);
135+
}
130136
}
131137
catch (ClassNotFoundException e) {
132-
logger.debug("Cannot load class", e);
138+
logger.debug("Cannot load class: {}", className);
139+
}
140+
catch (Exception e) {
141+
logger.debug("Error loading class: {}", className, e);
133142
}
134143
return null;
135144
}

0 commit comments

Comments
 (0)