Skip to content

Commit 65429d9

Browse files
committed
MethodToolCallback ToolExecutionException
- Handle the entire exception type when throwing ToolExecutionException Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
1 parent 8e972a4 commit 65429d9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

spring-ai-model/src/main/java/org/springframework/ai/tool/method/MethodToolCallback.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,10 @@ private Map<String, Object> extractToolArguments(String toolInput) {
132132
return JsonParser.fromJson(toolInput, new TypeReference<>() {
133133
});
134134
}
135-
catch (IllegalStateException ex) {
136-
if (ex.getCause() instanceof JsonProcessingException jsonExp) {
137-
logger.warn("Conversion from JSON failed", ex);
138-
throw new ToolExecutionException(this.getToolDefinition(), jsonExp);
139-
}
140-
throw ex;
135+
catch (Exception ex) {
136+
logger.warn("Conversion from JSON failed", ex);
137+
Throwable cause = (ex.getCause() instanceof JsonProcessingException) ? ex.getCause() : ex;
138+
throw new ToolExecutionException(this.getToolDefinition(), cause);
141139
}
142140
}
143141

@@ -168,12 +166,10 @@ private Object buildTypedArgument(@Nullable Object value, Type type) {
168166
String json = JsonParser.toJson(value);
169167
return JsonParser.fromJson(json, type);
170168
}
171-
catch (IllegalStateException ex) {
172-
if (ex.getCause() instanceof JsonProcessingException jsonExp) {
173-
logger.warn("Conversion from JSON failed", ex);
174-
throw new ToolExecutionException(this.getToolDefinition(), jsonExp);
175-
}
176-
throw ex;
169+
catch (Exception ex) {
170+
logger.warn("Conversion from JSON failed", ex);
171+
Throwable cause = (ex.getCause() instanceof JsonProcessingException) ? ex.getCause() : ex;
172+
throw new ToolExecutionException(this.getToolDefinition(), cause);
177173
}
178174
}
179175

0 commit comments

Comments
 (0)