Skip to content

Commit 1bcf9fb

Browse files
brunoborgesCopilot
andauthored
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>
1 parent fa2c650 commit 1bcf9fb

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

__tests__/distributors/graalvm-installer.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,20 @@ describe('GraalVMDistribution', () => {
10581058
'GraalVM Community does not provide early access builds'
10591059
);
10601060
});
1061+
1062+
it('should surface an error when the releases listing is not an array', async () => {
1063+
mockHttpClient.getJson.mockResolvedValue({
1064+
result: {message: 'API rate limit exceeded'},
1065+
statusCode: 403,
1066+
headers: {}
1067+
});
1068+
1069+
await expect(
1070+
(communityDistribution as any).findPackageForDownload('21')
1071+
).rejects.toThrow(
1072+
/Unexpected response while listing GraalVM Community releases.*HTTP status code: 403/s
1073+
);
1074+
});
10611075
});
10621076
});
10631077
});

dist/setup/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79300,7 +79300,17 @@ class GraalVMCommunityDistribution extends GraalVMDistribution {
7930079300
let releasesUrl = GRAALVM_COMMUNITY_RELEASES_URL;
7930179301
for (let pageIndex = 0; releasesUrl && pageIndex < util_1.MAX_PAGINATION_PAGES; pageIndex++) {
7930279302
const response = yield this.http.getJson(releasesUrl, headers);
79303-
const releases = Array.isArray(response.result) ? response.result : [];
79303+
// A successful GitHub releases listing is always a JSON array (possibly
79304+
// empty). Anything else indicates an unexpected/error payload (rate
79305+
// limiting, auth failure, etc.) that must be surfaced instead of being
79306+
// silently treated as "no releases", which would later look like a
79307+
// misleading "version not found" error.
79308+
if (!Array.isArray(response.result)) {
79309+
throw new Error(`Unexpected response while listing GraalVM Community releases from ${releasesUrl} ` +
79310+
`(HTTP status code: ${response.statusCode}). Expected a JSON array of releases. ` +
79311+
`Please check if the service is available at ${GRAALVM_COMMUNITY_DOWNLOAD_URL}.`);
79312+
}
79313+
const releases = response.result;
7930479314
if (releases.length === 0) {
7930579315
break;
7930679316
}

docs/advanced-usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ steps:
186186
distribution: 'graalvm-community'
187187
java-version: '21'
188188
- run: |
189-
java -cp java HelloWorldApp
190-
native-image -cp java HelloWorldApp
189+
java --version
190+
native-image --version
191191
```
192192

193193
### JetBrains

src/distributions/graalvm/installer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,20 @@ export class GraalVMCommunityDistribution extends GraalVMDistribution {
391391
headers
392392
);
393393

394-
const releases = Array.isArray(response.result) ? response.result : [];
394+
// A successful GitHub releases listing is always a JSON array (possibly
395+
// empty). Anything else indicates an unexpected/error payload (rate
396+
// limiting, auth failure, etc.) that must be surfaced instead of being
397+
// silently treated as "no releases", which would later look like a
398+
// misleading "version not found" error.
399+
if (!Array.isArray(response.result)) {
400+
throw new Error(
401+
`Unexpected response while listing GraalVM Community releases from ${releasesUrl} ` +
402+
`(HTTP status code: ${response.statusCode}). Expected a JSON array of releases. ` +
403+
`Please check if the service is available at ${GRAALVM_COMMUNITY_DOWNLOAD_URL}.`
404+
);
405+
}
406+
407+
const releases = response.result;
395408
if (releases.length === 0) {
396409
break;
397410
}

0 commit comments

Comments
 (0)