pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
69 stars 21 forks source link

[sdk/java] improve exception output #785

Open dixler opened 2 years ago

dixler commented 2 years ago

Hello!

Issue details

Was reviewing https://github.com/pulumi/examples/pull/1260

The error message could be better.

  pulumi:pulumi:Stack (gcp-java-gke-hello-world-dev):
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ----------------< com.pulumi:gcp-java-gke-hello-world >-----------------
    [INFO] Building gcp-java-gke-hello-world 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gcp-java-gke-hello-world ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/kdixler/Documents/examples/gcp-java-gke-hello-world/src/main/resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gcp-java-gke-hello-world ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO]
    [INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ gcp-java-gke-hello-world ---

    Aug 10, 2022 8:16:53 AM com.pulumi.deployment.internal.DeploymentImpl$DefaultEngineLogger errorAsync
    SEVERE: Running program [PID: 217938](/usr/lib/jvm/java-11-openjdk/bin/java -classpath /opt/maven/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/opt/maven/bin/m2.conf -Dmaven.home=/opt/maven -Dlibrary.jansi.path=/opt/maven/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/kdixler/Documents/examples/gcp-java-gke-hello-world org.codehaus.plexus.classworlds.launcher.Launcher --no-transfer-progress compile exec:java) failed with an unhandled exception:
    java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.orElseThrow(Optional.java:382)
        at gcpgke.App.stack(App.java:94)
        at com.pulumi.internal.PulumiInternal.lambda$runAsyncResult$2(PulumiInternal.java:77)
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1692)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

    error: Running program [PID: 217938](/usr/lib/jvm/java-11-openjdk/bin/java -classpath /opt/maven/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/opt/maven/bin/m2.conf -Dmaven.home=/opt/maven -Dlibrary.jansi.path=/opt/maven/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/kdixler/Documents/examples/gcp-java-gke-hello-world org.codehaus.plexus.classworlds.launcher.Launcher --no-transfer-progress compile exec:java) failed with an unhandled exception:
    java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.orElseThrow(Optional.java:382)
        at gcpgke.App.stack(App.java:94)
        at com.pulumi.internal.PulumiInternal.lambda$runAsyncResult$2(PulumiInternal.java:77)
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1692)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
    error: an unhandled error occurred: '/usr/bin/mvn /usr/bin/mvn --no-transfer-progress compile exec:java' exited with non-zero exit code: 32

Work items

Affected area/feature

pawelprazak commented 2 years ago

817 might be a related related to this one

pawelprazak commented 2 years ago

regarding:

improve missing config value error message(indicate the missing config value and how to set it)

ctx.config.get("bleh") returns an Optional so there is no error, and ctx.config.require("bleh") works as expected:

Diagnostics:
  pulumi:pulumi:Stack (random-java-random):
    error: Missing required configuration variable 'random:bleh'
        please set a value using the command `pulumi config set random:bleh <value>`
    error: an unhandled error occurred: '/usr/local/bin/mvn /usr/local/bin/mvn -Dorg.slf4j.simpleLogger.defaultLogLevel=warn --no-transfer-progress compile exec:java' exited with non-zero exit code: 32

    Aug 26, 2022 10:55:52 AM com.pulumi.deployment.internal.DeploymentImpl$DefaultEngineLogger errorAsync
    SEVERE: Missing required configuration variable 'random:bleh'
        please set a value using the command `pulumi config set random:bleh <value>`

please let me know what improvements you've had in mind :)

pawelprazak commented 2 years ago

I've made a small change that should address the most visible problem of perceived duplication.

After changes:

Pawes-MacBook-Pro:random pprazak$ pulumi up
Please choose a stack, or create a new one: java-random
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):
Previewing update (java-random):
     Type                 Name                Plan     Info
     pulumi:pulumi:Stack  random-java-random           1 error; 16 messages

Diagnostics:
  pulumi:pulumi:Stack (random-java-random):
    [ERROR] COMPILATION ERROR :
    [ERROR] /Users/pprazak/repos/pulumi-java/tests/examples/random/src/main/java/com/pulumi/example/random/App.java:[29,13] cannot find symbol
      symbol:   method ctxexport(java.lang.String,com.pulumi.core.Output<java.lang.String>)
      location: class com.pulumi.example.random.App
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project random: Compilation failure
    [ERROR] /Users/pprazak/repos/pulumi-java/tests/examples/random/src/main/java/com/pulumi/example/random/App.java:[29,13] cannot find symbol
    [ERROR]   symbol:   method ctxexport(java.lang.String,com.pulumi.core.Output<java.lang.String>)
    [ERROR]   location: class com.pulumi.example.random.App
    [ERROR]
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

    error: an unhandled error occurred: '/usr/local/bin/mvn /usr/local/bin/mvn -Dorg.slf4j.simpleLogger.defaultLogLevel=warn --no-transfer-progress compile exec:java' exited with non-zero exit code: 1

Also pulumi about no longer display exceptions by default:

Pawes-MacBook-Pro:random pprazak$ pulumi about
CLI
Version      3.38.0
Go Version   go1.19
Go Compiler  gc

Plugins
NAME  VERSION
java  unknown

Host
OS       darwin
Version  12.4
Arch     x86_64

This project is written in java: executable='/Users/pprazak/.jenv/shims/java' version='openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)' javac='11.0.11' maven='Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)' gradle='7.5.1' java='/Users/pprazak/.jenv/shims/java'

Backend
Name           Pawes-MacBook-Pro.local
URL            file://~
User           pprazak
Organizations

No dependencies found

Pulumi locates its logs in /var/folders/nr/rqhf2hvn3wn8q_mjysz2gq6m0000gn/T/ by default
warning: Failed to get information about the current stack: No current stack