From 1bcf9fb12cf4aa7d266a90ae39939e61372fe520 Mon Sep 17 00:00:00 2001 From: Bruno Borges Date: Tue, 23 Jun 2026 13:37:44 -0400 Subject: [PATCH] dist: Address Copilot review suggestions from PR #1042 (GraalVM Community) (#1059) - installer: surface a clear error when the GraalVM Community releases listing is not a JSON array, instead of silently treating an error payload (rate limit, auth failure, etc.) as "no releases" which later surfaced as a misleading "version not found" error. - docs: fix the GraalVM Community advanced-usage example to check the installed binary versions (java/native-image --version) rather than running a non-existent HelloWorldApp classpath that fails when copied. - tests: cover the new non-array release listing error path. Rebuilt dist bundle. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- __tests__/distributors/graalvm-installer.test.ts | 14 ++++++++++++++ dist/setup/index.js | 12 +++++++++++- docs/advanced-usage.md | 4 ++-- src/distributions/graalvm/installer.ts | 15 ++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/__tests__/distributors/graalvm-installer.test.ts b/__tests__/distributors/graalvm-installer.test.ts index 155e3d9e..beefbd13 100644 --- a/__tests__/distributors/graalvm-installer.test.ts +++ b/__tests__/distributors/graalvm-installer.test.ts @@ -1058,6 +1058,20 @@ describe('GraalVMDistribution', () => { 'GraalVM Community does not provide early access builds' ); }); + + it('should surface an error when the releases listing is not an array', async () => { + mockHttpClient.getJson.mockResolvedValue({ + result: {message: 'API rate limit exceeded'}, + statusCode: 403, + headers: {} + }); + + await expect( + (communityDistribution as any).findPackageForDownload('21') + ).rejects.toThrow( + /Unexpected response while listing GraalVM Community releases.*HTTP status code: 403/s + ); + }); }); }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 007b4849..bbf320eb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -79300,7 +79300,17 @@ class GraalVMCommunityDistribution extends GraalVMDistribution { let releasesUrl = GRAALVM_COMMUNITY_RELEASES_URL; for (let pageIndex = 0; releasesUrl && pageIndex < util_1.MAX_PAGINATION_PAGES; pageIndex++) { const response = yield this.http.getJson(releasesUrl, headers); - const releases = Array.isArray(response.result) ? response.result : []; + // A successful GitHub releases listing is always a JSON array (possibly + // empty). Anything else indicates an unexpected/error payload (rate + // limiting, auth failure, etc.) that must be surfaced instead of being + // silently treated as "no releases", which would later look like a + // misleading "version not found" error. + if (!Array.isArray(response.result)) { + throw new Error(`Unexpected response while listing GraalVM Community releases from ${releasesUrl} ` + + `(HTTP status code: ${response.statusCode}). Expected a JSON array of releases. ` + + `Please check if the service is available at ${GRAALVM_COMMUNITY_DOWNLOAD_URL}.`); + } + const releases = response.result; if (releases.length === 0) { break; } diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index b12a49b9..58301be9 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -186,8 +186,8 @@ steps: distribution: 'graalvm-community' java-version: '21' - run: | - java -cp java HelloWorldApp - native-image -cp java HelloWorldApp + java --version + native-image --version ``` ### JetBrains diff --git a/src/distributions/graalvm/installer.ts b/src/distributions/graalvm/installer.ts index 2b2442f8..861cf12a 100644 --- a/src/distributions/graalvm/installer.ts +++ b/src/distributions/graalvm/installer.ts @@ -391,7 +391,20 @@ export class GraalVMCommunityDistribution extends GraalVMDistribution { headers ); - const releases = Array.isArray(response.result) ? response.result : []; + // A successful GitHub releases listing is always a JSON array (possibly + // empty). Anything else indicates an unexpected/error payload (rate + // limiting, auth failure, etc.) that must be surfaced instead of being + // silently treated as "no releases", which would later look like a + // misleading "version not found" error. + if (!Array.isArray(response.result)) { + throw new Error( + `Unexpected response while listing GraalVM Community releases from ${releasesUrl} ` + + `(HTTP status code: ${response.statusCode}). Expected a JSON array of releases. ` + + `Please check if the service is available at ${GRAALVM_COMMUNITY_DOWNLOAD_URL}.` + ); + } + + const releases = response.result; if (releases.length === 0) { break; }