From dcddd86cb2be8a025d1a738db403ce922a1286a2 Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Sat, 14 Nov 2026 12:21:37 +0100 Subject: [PATCH 1/2] CAMEL-26933: camel-jbang-plugin-validate - validate exits with 66 for a missing file or nothing to validate 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. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claus Ibsen --- .../pages/camel-4x-upgrade-guide-4_24.adoc | 7 +++++++ .../validate/SourceValidateCommand.java | 5 +++++ .../validate/YamlNormalizeCommand.java | 4 +++- .../validate/YamlValidateCommand.java | 4 ++++ .../commands/validate/ValidateJsonTest.java | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) 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 028422a474ff9..81056d0e51d98 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 855d41592a1b7..469628479ef52 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.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 Integer doCall() throws Exception { 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 bce5ae5394da6..db2bea6bc1842 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.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 Integer doCall() throws Exception { } } 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 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 65ddf6c8564ca..630ee18706d8b 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 Integer doCall() throws Exception { Map> 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 588f65b187a14..813ec401404c5 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 @@ void nothingToValidateIsNotFound() throws Exception { 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); From e3f2d4f8152419954afb8dff0e0caf537e76c300 Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Sat, 14 Nov 2026 12:56:37 +0100 Subject: [PATCH 2/2] 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 Signed-off-by: Claus Ibsen --- .../org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3c30699d2ab2d..6579f183beb78 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 void quit(int exitCode) { 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());