paketo-buildpacks / libjvm

A library and helper applications that form the basis for building the different Paketo-style JVM-providing buildpacks
Apache License 2.0
19 stars 21 forks source link

Better error message if buildpack can not provide the desired JRE #434

Closed anthonydahanne closed 2 weeks ago

anthonydahanne commented 3 weeks ago

Describe the Enhancement

In case the user has built with Java 22 for example, and then try to use the latest Paketo Buildpacks (that recently removed 22), the error message can be hard to decipher:

[INFO]     [creator]         Using Java version 22 extracted from MANIFEST.MF
[INFO]     [creator]       No valid JRE available, providing matching JDK instead. Using a JDK at runtime has security implications.
[INFO]     [creator]        : Contributing to layer
[INFO]     [creator]       Warning: Dependency has no SHA256. Skipping cache.
[INFO]     [creator]         Downloading from 
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to get dependency . see DEBUG log level
[INFO]     [creator]     ERROR: failed to build: exit status 1

This is due to the fact we don't display specific error messages for this case https://github.com/paketo-buildpacks/libjvm/blob/main/build.go#L317-L335

Possible Solution

       if !jreSkipped && jreMissing {
        // we wanted a JRE, but it's missing 
                subMsg := "No JRE matching the desired Java version is provided by the buildpack, try changing the Java version required"
        msg = fmt.Sprintf("%s. %s", subMsg, msg)
    }

Motivation

Make the error message clearer