Skip to content

Refactor error handling and improve test logging for installers#989

Open
chiranjib-swain wants to merge 4 commits intoactions:mainfrom
chiranjib-swain:improve-java-error-messaging
Open

Refactor error handling and improve test logging for installers#989
chiranjib-swain wants to merge 4 commits intoactions:mainfrom
chiranjib-swain:improve-java-error-messaging

Conversation

@chiranjib-swain
Copy link
Contributor

@chiranjib-swain chiranjib-swain commented Mar 18, 2026

Description:
This PR standardizes the “version not found” error handling across Java distribution installers by introducing a shared helper in JavaBase. It also updates installer and caching tests to align with the new message format and reduces noisy core.error output during test runs.

Related issue:
#977, #978

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

Copilot AI review requested due to automatic review settings March 18, 2026 05:27
@chiranjib-swain chiranjib-swain requested a review from a team as a code owner March 18, 2026 05:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes “version not found” error handling across Java distribution installers by introducing a shared helper on JavaBase, and updates installer/caching tests to use the new message format while reducing noisy core.error output during test runs.

Changes:

  • Added JavaBase.createVersionNotFoundError(...) to generate consistent, context-rich error messages (with optional available-versions truncation).
  • Refactored multiple distribution installers to throw the standardized error instead of bespoke strings.
  • Updated Jest suites to align assertions with the new messages and to consistently mock core.error to suppress test log noise.

Reviewed changes

Copilot reviewed 33 out of 34 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/distributions/base-installer.ts Adds createVersionNotFoundError helper for standardized errors.
src/distributions/adopt/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/corretto/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/dragonwell/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/graalvm/installer.ts Switches to the helper for some “not found” paths and appends a GraalVM URL hint on 404.
src/distributions/jetbrains/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/liberica/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/microsoft/installer.ts Uses the new helper when no satisfied version is found (includes manifest versions).
src/distributions/oracle/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/sapmachine/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/semeru/installer.ts Uses the new helper and adds platform context to the error.
src/distributions/temurin/installer.ts Uses the new helper when no satisfied version is found.
src/distributions/zulu/installer.ts Uses the new helper when no satisfied version is found.
dist/setup/index.js Updates the compiled distribution bundle to reflect source changes.
tests/distributors/adopt-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/base-installer.test.ts Updates version-not-found expectations and adds unit tests for the helper.
tests/distributors/corretto-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/dragonwell-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/graalvm-installer.test.ts Updates error expectations and removes assertions tied to old core.error logging behavior.
tests/distributors/jetbrains-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/liberica-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/liberica-linux-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/liberica-windows-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/local-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/microsoft-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/oracle-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/sapmachine-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/semeru-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/temurin-installer.test.ts Mocks core.error to suppress logs during tests.
tests/distributors/zulu-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/zulu-linux-installer.test.ts Updates error expectations and mocks core.error.
tests/distributors/zulu-windows-installer.test.ts Updates error expectations and mocks core.error.
tests/cache.test.ts Mocks core.error and strengthens cleanup of Jest mocks between tests.
tests/cleanup-java.test.ts Mocks core.error and strengthens cleanup of Jest mocks between tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@jsoref jsoref left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to test this to give additional feedback, but based on the tests, this is my first pass.

(distribution as any).findPackageForDownload('17.0.99')
).rejects.toThrow(
'Could not find GraalVM for SemVer 17.0.99. Please check if this version is available at https://download.oracle.com/graalvm'
"Could not find satisfied version for SemVer '17.0.99'"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, this message is lousy. satisfied isn't compatible with could not find.

You could say could not satisfy or could not find a satisfying, but the text here doesn't work.

expect(core.error).toHaveBeenCalledWith(
'Available versions: 23-ea-20240716, 23-ea-20240709'
).rejects.toThrow(
"No EA build is marked as 'latest' for version range '23-ea'. Available EA versions: 23-ea-20240716, 23-ea-20240709."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard to read. If there's a range, you should use some range notification markers, e.g. ['23-ea'... '23-ea']. Otherwise, it looks like the range is ['23'... 'ea'], but I don't think it is given that a version appears to be '23-ea-something'. And note that you probably should quote (or `) the available versions, or remove that quoting from the first part.

);
// Create the standard error with additional hint about checking the download URL
const error = this.createVersionNotFoundError(range);
error.message += `\nPlease check if this version is available at ${GRAALVM_DL_BASE}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message isn't actionable. If I find that it is available there, what am I supposed to do?

@jsoref
Copy link

jsoref commented Mar 20, 2026

Before

https://github.com/check-spelling-sandbox/setup-java/actions/runs/23344583858

Annotations

9 errors
Basic validation / build (ubuntu-latest)
Process completed with exit code 1.
Basic validation / build (ubuntu-latest)
Java setup process failed due to: Available version not found
Basic validation / build (ubuntu-latest)
Java setup process failed due to: Available version not found
Basic validation / build (macos-latest)
Process completed with exit code 1.
Basic validation / build (macos-latest)
Java setup process failed due to: Available version not found
Basic validation / build (macos-latest)
Java setup process failed due to: Available version not found
Basic validation / build (windows-latest)
Process completed with exit code 1.
Basic validation / build (windows-latest)
Java setup process failed due to: Available version not found
Basic validation / build (windows-latest)
Java setup process failed due to: Available version not found

After

https://github.com/check-spelling-sandbox/setup-java/actions/runs/23345876163

Annotations

3 errors
Basic validation / build (ubuntu-latest)
Process completed with exit code 1.
Basic validation / build (macos-latest)
Process completed with exit code 1.
Basic validation / build (windows-latest)
Process completed with exit code 1.


For the rest of it, I'm looking for something like:

::notice ::fast-xml-parser  4.0.0-beta.3 - 5.5.6 / Severity: high / fast-xml-parser affected by numeric entity expansion bypassing all entity expansion limits (incomplete fix for CVE-2026-26278) - https://github.com/advisories/GHSA-8gc5-j5rx-235r
::notice ::flatted  <=3.4.1 / Severity: high / flatted vulnerable to unbounded recursion DoS in parse() revive phase - https://github.com/advisories/GHSA-25h7-pfq9-p65f
::notice ::js-yaml  <3.14.2 / Severity: moderate / js-yaml has prototype pollution in merge (<<) - https://github.com/advisories/GHSA-mh29-5h37-fv8m
::notice ::undici  <=6.23.0 / Severity: high / Undici has an unbounded decompression chain in HTTP responses on Node.js Fetch API via Content-Encoding leads to resource exhaustion - https://github.com/advisories/GHSA-g9mf-h72j-4rw9

This is roughly the first 3 lines from each audit report (the package, the severity, and the first line of description).

You could be fancy and use ::warning or ::error instead, and you could use title= too, e.g.

::error title=Dependency fast-xml-parser  4.0.0-beta.3 - 5.5.6 (Severity: high)::fast-xml-parser affected by numeric entity expansion bypassing all entity expansion limits (incomplete fix for CVE-2026-26278) - https://github.com/advisories/GHSA-8gc5-j5rx-235r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants