gnodet-bot commented on code in PR #30003:
URL: https://github.com/apache/camel/pull/30003#discussion_r4577475626


##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelTest.java:
##########
@@ -1297,6 +1297,69 @@ public ChatResponse chatWithTools(String systemPrompt, 
List<Message> messages, L
         }
     }
 
+    // ---- what ends a turn is shown and logged, also an Error and a failure 
with no message ----
+
+    @Test
+    void aTurnThatEndsInAnErrorIsShownAndLogged() throws Exception {
+        // a plugin jar built after the core jar it calls (Nov 14 2026): each 
answer ended with nothing shown or logged
+        AiPanel panel = askFailing(new NoSuchMethodError("'java.util.List 
AnswerChecks.checkCode(java.lang.String)'"));
+
+        AiPanel.ConversationEntry last = 
panel.conversationForTesting().get(panel.conversationForTesting().size() - 1);
+        assertEquals(AiRole.ERROR, last.role());
+        assertTrue(last.text().startsWith("The jars of the Camel CLI do not 
match"), last.text());
+        assertTrue(last.text().contains("NoSuchMethodError"), last.text());
+        assertTrue(panel.getActivityLog().stream()
+                .anyMatch(e -> e.level() == AiPanel.LogLevel.ERROR && 
e.detail().contains("NoSuchMethodError")));
+        assertFalse(panel.isThinkingForTesting());
+    }
+
+    @Test
+    void aFailureWithNoMessageIsNotBlank() throws Exception {
+        AiPanel panel = askFailing(new IllegalStateException());
+
+        AiPanel.ConversationEntry last = 
panel.conversationForTesting().get(panel.conversationForTesting().size() - 1);
+        assertEquals(AiRole.ERROR, last.role());
+        assertEquals("java.lang.IllegalStateException", last.text());
+        assertTrue(panel.getActivityLog().stream()
+                .anyMatch(e -> e.level() == AiPanel.LogLevel.ERROR && 
"java.lang.IllegalStateException".equals(e.detail())));
+    }
+
+    private static AiPanel askFailing(Throwable failure) throws Exception {
+        AiPanel panel = new AiPanel();
+        panel.setToolRegistryForTesting(new TuiToolRegistry(null));
+        panel.setClientForTesting(new FailingLlmClient(failure));
+        panel.open();
+        type(panel, "what does this app do");
+        panel.handleKeyEvent(KeyEvent.ofKey(KeyCode.ENTER, KeyModifiers.NONE));
+        await().atMost(10, TimeUnit.SECONDS).until(() -> 
!panel.isAgentThreadRunningForTesting());
+        return panel;
+    }
+
+    /** Fails its first request with the given failure. */
+    private static final class FailingLlmClient extends LlmClient {
+
+        private final Throwable failure;
+
+        FailingLlmClient(Throwable failure) {
+            this.failure = failure;
+            withModel("test-model");
+            withApiType(ApiType.openai);
+        }
+
+        @Override
+        public boolean detectEndpoint() {
+            return true;
+        }
+
+        @Override
+        public ChatResponse chatWithTools(String systemPrompt, List<Message> 
messages, List<ToolDef> tools) {
+            if (failure instanceof Error error) {
+                throw error;
+            }
+            throw (RuntimeException) failure;
+        }

Review Comment:
   💡 **Nit (test code):** The unchecked `(RuntimeException)` cast works for the 
two current call sites, but a future caller passing a checked `Exception` (e.g. 
`IOException`) would get a `ClassCastException` that masks the intent. Using 
`instanceof` is both safer and cleaner:
   
   ```suggestion
           public ChatResponse chatWithTools(String systemPrompt, List<Message> 
messages, List<ToolDef> tools) {
               if (failure instanceof Error error) {
                   throw error;
               }
               if (failure instanceof RuntimeException rte) {
                   throw rte;
               }
               throw new RuntimeException(failure);
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to