quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.56k stars 2.62k forks source link

`quarkus`cli always return 1 for exitcode for plugin commands #42752

Closed cescoffier closed 2 weeks ago

cescoffier commented 2 weeks ago

Describe the bug

I have a command with the following main method:

public static void main(String[] args) {
        int exitCode = new CommandLine(new TlsCommand()).execute(args);
        System.exit(exitCode);
}

The exitCode is 0.

However, when running with the quarkus CLI, I get a 1 status, breaking all the scripts:

error: Recipe `generate-unsigned-certificate` failed on line 6 with exit code 1

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

quarkus-bot[bot] commented 2 weeks ago

/cc @ebullient (cli), @maxandersen (cli)

maxandersen commented 2 weeks ago

@cescoffier running with quarkus cli how? as a quarkus plugin or ?

cescoffier commented 2 weeks ago

Like this:

generate-unsigned-certificate:
    rm -Rf .certs
    quarkus tls generate-certificate --name=local --password=secret --self-signed

The workaround is to append || true to the quarkus command, but it should not be required.

maxandersen commented 2 weeks ago

okey, reproduced with simple code like this:

///usr/bin/env jbang "$0" "$@" ; exit $?

import static java.lang.System.*;

public class qhello {

    public static void main(String... args) {

        int exitCode = 0;
        if (args.length > 0) {
            try {
                exitCode = Integer.parseInt(args[0]);
            } catch (NumberFormatException e) {
                // If parsing fails, exitCode remains 0
            }
        }
        out.println("Exit with: " + exitCode);
        System.exit(exitCode);
    }
}

when running this with jbang the exit code is bubbling up correctly but when running with quarkus cli it is for some reason always 1.

 jbang qhello.java 4r2
[jbang] Building jar for qhello.java...
Exit with: 0
❯ jbang qhello.java 42; echo $?
Exit with: 42
42
❯ quarkus qhello 42; echo $?
Exit with: 42
1