Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ public String process(ToolExecutionException exception) {
if (this.alwaysThrow) {
throw exception;
}
logger.debug("Exception thrown by tool: {}. Message: {}", exception.getToolDefinition().name(),
exception.getMessage());
return exception.getMessage();
String message = exception.getMessage();
if (message == null || message.isBlank()) {
message = "Exception occurred in tool: " + exception.getToolDefinition().name() + " ("
+ cause.getClass().getSimpleName() + ")";
}
logger.debug("Exception thrown by tool: {}. Message: {}", exception.getToolDefinition().name(), message);
return message;
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ void processReturnsMessage() {
assertThat(result).isEqualTo(this.toolException.getMessage());
}

@Test
void processReturnsFallbackMessageWhenNull() {
DefaultToolExecutionExceptionProcessor processor = DefaultToolExecutionExceptionProcessor.builder().build();

ToolExecutionException exception = new ToolExecutionException(this.toolDefinition, new IllegalStateException());

String result = processor.process(exception);

assertThat(result).isEqualTo("Exception occurred in tool: toolName (IllegalStateException)");
}

@Test
void processReturnsFallbackMessageWhenBlank() {
DefaultToolExecutionExceptionProcessor processor = DefaultToolExecutionExceptionProcessor.builder().build();

ToolExecutionException exception = new ToolExecutionException(this.toolDefinition, new RuntimeException(" "));

String result = processor.process(exception);

assertThat(result).isEqualTo("Exception occurred in tool: toolName (RuntimeException)");
}

@Test
void processAlwaysThrows() {
DefaultToolExecutionExceptionProcessor processor = DefaultToolExecutionExceptionProcessor.builder()
Expand Down