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


##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/RouteDiagramTools.java:
##########
@@ -127,34 +131,55 @@ public RouteDiagramResult camel_render_route_diagram(
             if (textMode) {
                 String asciiContent = success ? Files.readString(out.toPath()) 
: null;
                 String message = success
-                        ? withNotes("ASCII diagram generated (" + size + " 
bytes)", capturingPrinter)
+                        ? withNotes("ASCII diagram generated (" + size + " 
bytes)", capturingPrinter, resolvedOutput)
                         : "Failed to render diagram (exit code " + exit + "): 
" + capturingPrinter.getOutput();
+                if (tempText) {
+                    // the diagram is in the answer: no file is left behind 
for each call (CAMEL-26932)
+                    Files.deleteIfExists(out.toPath());
+                    return new RouteDiagramResult(success, null, size, 
message, asciiContent);
+                }
                 return new RouteDiagramResult(success, resolvedOutput, size, 
message, asciiContent);
             }
 
             String message = success
-                    ? withNotes("Diagram saved to: " + resolvedOutput, 
capturingPrinter)
+                    ? withNotes("Diagram saved to: " + resolvedOutput, 
capturingPrinter, resolvedOutput)
                     : "Failed to render diagram (exit code " + exit + "): " + 
capturingPrinter.getOutput();
             return new RouteDiagramResult(success, resolvedOutput, size, 
message, null);
         } catch (CliException e) {
             // an expected failure, such as a source file without routes, or a 
filter that matches no route
+            deleteTempText(tempText, resolvedOutput);
             return new RouteDiagramResult(
                     false, resolvedOutput, 0L,
                     "Failed to render diagram (exit code " + e.getExitCode() + 
"): " + e.getMessage(), null);
         } catch (Throwable e) {
+            deleteTempText(tempText, resolvedOutput);
             throw new ToolCallException(
                     "Failed to render route diagram (" + 
e.getClass().getName() + "): " + e.getMessage(), null);
         }

Review Comment:
   🐛 **Minor inconsistency:** `deleteTempText` removes the temp file when 
`tempText` is true, but `resolvedOutput` (the now-deleted path) is still passed 
to `RouteDiagramResult`. The success path at the `tempText` branch correctly 
returns `null` for `outputFile`. Suggested fix:
   
   ```suggestion
               deleteTempText(tempText, resolvedOutput);
               return new RouteDiagramResult(
                       false, tempText ? null : resolvedOutput, 0L,
                       "Failed to render diagram (exit code " + e.getExitCode() 
+ "): " + e.getMessage(), null);
   ```



-- 
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