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

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


The following commit(s) were added to refs/heads/main by this push:
     new d1bd74938e0a CAMEL-26933: camel-jbang-plugin-validate - validate exits 
with 66 for a missing file or nothing to validate (#29926)
d1bd74938e0a is described below

commit d1bd74938e0ad658b5880da1ed9dfc78c9fc4f2b
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 14 19:26:21 2026 +0100

    CAMEL-26933: camel-jbang-plugin-validate - validate exits with 66 for a 
missing file or nothing to validate (#29926)
    
    validate yaml of a missing file reported a validation error with exit 1, 
while validate
    source and validate properties exit 66; validate source said "Validation 
success
    (files:0)" and validate normalize exited 0 when no file could be handled. 
All three
    exit 66 now, with a message that says so.
    
    CAMEL-26933: camel-launcher - the validate test checks a file with a 
validation error, not a missing file
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc       |  7 +++++++
 .../core/commands/validate/SourceValidateCommand.java |  5 +++++
 .../core/commands/validate/YamlNormalizeCommand.java  |  4 +++-
 .../core/commands/validate/YamlValidateCommand.java   |  4 ++++
 .../core/commands/validate/ValidateJsonTest.java      | 19 +++++++++++++++++++
 .../camel/dsl/jbang/launcher/CamelLauncherTest.java   |  2 +-
 6 files changed, 39 insertions(+), 2 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index f618b71cd1db..ddb0101eda9d 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -1433,6 +1433,13 @@ built for Camel 4.24:
 * A test sets the options of a command with 
`CommandLineTestHelper.parse(command, args...)` (in the test jar of
   `camel-jbang-core`) instead of `CommandLine.populateCommand`.
 
+=== camel-jbang - camel validate exits with 66 for a missing file or nothing 
to validate
+
+`camel validate yaml` of a file that does not exist now exits with code `66` 
(file not found), as `validate source` and
+`validate properties` do; before, it reported a validation error with code 
`1`. `camel validate source` and
+`camel validate normalize` given no file they can handle (such as `notes.txt`) 
now exit with code `66`; before, they
+reported success with code `0`.
+
 === camel-jbang - plugins declare which commands they contribute to
 
 A CLI plugin can now declare which built-in commands it participates in beyond 
its own command, using the
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/SourceValidateCommand.java
 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/SourceValidateCommand.java
index 855d41592a1b..469628479ef5 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/SourceValidateCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/SourceValidateCommand.java
@@ -31,6 +31,7 @@ import org.apache.camel.catalog.CamelCatalog;
 import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.commands.ai.SourceValidator;
+import org.apache.camel.dsl.jbang.core.common.CliException;
 import org.apache.camel.dsl.jbang.core.common.JsonOutput;
 import org.apache.camel.dsl.yaml.validator.YamlValidator;
 
@@ -76,6 +77,10 @@ public class SourceValidateCommand extends CamelCommand {
             reports.put(n, SourceValidator.validate(f.getName(), content, 
catalog, null,
                     parent != null ? parent.toPath() : null, schemaValidator));
         }
+        if (reports.isEmpty()) {
+            // before, "Validation success (files:0)" with exit code 0
+            throw CliException.fileNotFound("No files to validate (YAML, XML, 
Java and properties files)");
+        }
         int count = reports.values().stream().mapToInt(List::size).sum();
         if (jsonOutput) {
             JsonOutput.printList(printer(),
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
index bce5ae5394da..db2bea6bc184 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
@@ -41,6 +41,7 @@ import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
 import org.apache.camel.dsl.jbang.core.commands.Run;
+import org.apache.camel.dsl.jbang.core.common.CliException;
 import org.apache.camel.dsl.jbang.run.common.CamelJBangConstants;
 import org.apache.camel.main.BaseMainSupport;
 import org.apache.camel.main.KameletMain;
@@ -91,7 +92,8 @@ public class YamlNormalizeCommand extends CamelCommand {
             }
         }
         if (matched.isEmpty()) {
-            return 0;
+            // before, exit code 0 with no output
+            throw CliException.fileNotFound("No YAML files to normalize");
         }
         // a Kamelet loads as a route template: its template is normalized and 
put back into the Kamelet file
         Map<String, String> kamelets = new LinkedHashMap<>();
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlValidateCommand.java
 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlValidateCommand.java
index 65ddf6c8564c..630ee18706d8 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlValidateCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlValidateCommand.java
@@ -83,6 +83,10 @@ public class YamlValidateCommand extends CamelCommand {
         Map<String, List<Error>> reports = new LinkedHashMap<>();
         for (String n : files) {
             if (matchFile(n)) {
+                if (!new File(n).isFile()) {
+                    // as validate source and validate properties: before, a 
validation error with exit code 1
+                    throw CliException.fileNotFound("File not found: " + n);
+                }
                 var report = new ArrayList<>(validator.validate(new File(n)));
                 if (camelCatalog != null && report.isEmpty()) {
                     // the schema is fine: check what the schema cannot, 
endpoint URIs and simple expressions
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/test/java/org/apache/camel/dsl/jbang/core/commands/validate/ValidateJsonTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/test/java/org/apache/camel/dsl/jbang/core/commands/validate/ValidateJsonTest.java
index 588f65b187a1..813ec401404c 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/test/java/org/apache/camel/dsl/jbang/core/commands/validate/ValidateJsonTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/test/java/org/apache/camel/dsl/jbang/core/commands/validate/ValidateJsonTest.java
@@ -121,6 +121,25 @@ class ValidateJsonTest {
         assertThat(e.getMessage()).isEqualTo("No properties files to 
validate");
     }
 
+    @Test
+    void theCommandsAgreeOnMissingFilesAndNothingToDo() throws Exception {
+        // validate yaml reported a validation error with exit code 1 for a 
missing file, validate source said
+        // "Validation success (files:0)" and validate normalize exited 0 for 
nothing to do (CAMEL-26933)
+        String missing = dir.resolve("nope.yaml").toString();
+        CliException e = assertThrows(CliException.class, () -> run(new 
YamlValidateCommand(main()), missing));
+        assertThat(e.getExitCode()).isEqualTo(CliExitCode.FILE_NOT_FOUND);
+        assertThat(e.getMessage()).isEqualTo("File not found: " + missing);
+
+        Path text = Files.writeString(dir.resolve("notes.txt"), "not a route");
+        e = assertThrows(CliException.class, () -> run(new 
SourceValidateCommand(main()), text.toString()));
+        assertThat(e.getExitCode()).isEqualTo(CliExitCode.FILE_NOT_FOUND);
+        assertThat(e.getMessage()).startsWith("No files to validate");
+
+        e = assertThrows(CliException.class, () -> run(new 
YamlNormalizeCommand(main()), text.toString()));
+        assertThat(e.getExitCode()).isEqualTo(CliExitCode.FILE_NOT_FOUND);
+        assertThat(e.getMessage()).isEqualTo("No YAML files to normalize");
+    }
+
     private CamelJBangMain main() {
         printer = new StringPrinter();
         return new CamelJBangMain().withPrinter(printer);
diff --git 
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java
 
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java
index 3c30699d2ab2..6579f183beb7 100644
--- 
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java
+++ 
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java
@@ -185,7 +185,7 @@ public class CamelLauncherTest {
         main.setOut(new PrintStreamPrinter(ps));
 
         // Run the validate command
-        main.execute("validate", "yaml", "src/test/resources/cheese.yaml");
+        main.execute("validate", "yaml", "src/test/resources/bad.yaml");
 
         Assertions.assertEquals(1, code.get());
 

Reply via email to