This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 74497f2e2602 CAMEL-23111: camel-jbang - camel run will log all fatal 
errors using LOG so they can be captured by configured logging settings, which 
may be sending logs to monitoring systems. Although camel run is only/primary 
for development purpose. (#21671)
74497f2e2602 is described below

commit 74497f2e2602bb7266f21700a92a0d9539aa454a
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Mar 2 11:38:03 2026 +0100

    CAMEL-23111: camel-jbang - camel run will log all fatal errors using LOG so 
they can be captured by configured logging settings, which may be sending logs 
to monitoring systems. Although camel run is only/primary for development 
purpose. (#21671)
---
 .../org/apache/camel/dsl/jbang/core/commands/Run.java     | 15 ++++++++-------
 .../src/main/java/org/apache/camel/main/KameletMain.java  |  7 +++++++
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 935f8d603fc6..45686e240080 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -1711,14 +1711,15 @@ public class Run extends CamelCommand {
     }
 
     protected int runKameletMain(KameletMain main) throws Exception {
-        main.start();
-        main.run();
-
-        // cleanup and delete log file
-        if (logFile != null) {
-            FileUtil.deleteFile(logFile);
+        try {
+            main.start();
+            main.run();
+        } finally {
+            // cleanup and delete log file
+            if (logFile != null) {
+                FileUtil.deleteFile(logFile);
+            }
         }
-
         return main.getExitCode();
     }
 
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index a1f4bbb760f9..4aa9561ff965 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -171,6 +171,13 @@ public class KameletMain extends MainCommandLineSupport {
         // normal exit
     }
 
+    @Override
+    protected void doFail(Exception e) {
+        // ensure any unhandled fatal errors are also logged before 
terminating process
+        LOG.error("Error starting Camel: {}", e, e);
+        super.doFail(e);
+    }
+
     /**
      * Binds the given <code>name</code> to the <code>bean</code> object, so 
that it can be looked up inside the
      * CamelContext this command line tool runs with.

Reply via email to