mirror of
https://github.com/graalvm/setup-graalvm.git
synced 2025-02-23 12:20:10 +08:00
Improve error message when url not found.
This commit is contained in:
parent
7c84ab1ba7
commit
4aba115fa5
25
__tests__/graalvm.test.ts
Normal file
25
__tests__/graalvm.test.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import * as path from 'path'
|
||||||
|
import * as graalvm from '../src/graalvm'
|
||||||
|
import {expect, test} from '@jest/globals'
|
||||||
|
|
||||||
|
process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
|
||||||
|
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')
|
||||||
|
|
||||||
|
test('request invalid version/javaVersion', async () => {
|
||||||
|
for (var combination of [
|
||||||
|
['22.3.0', '7'],
|
||||||
|
['22.3', '17'],
|
||||||
|
['22.3', '7']
|
||||||
|
]) {
|
||||||
|
let error = new Error('unexpected')
|
||||||
|
try {
|
||||||
|
await graalvm.setUpGraalVMRelease('', combination[0], combination[1])
|
||||||
|
} catch (err) {
|
||||||
|
error = err
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).not.toBeUndefined()
|
||||||
|
expect(error.message).toContain('Failed to download')
|
||||||
|
expect(error.message).toContain('Are you sure version')
|
||||||
|
}
|
||||||
|
})
|
20
dist/main/index.js
generated
vendored
20
dist/main/index.js
generated
vendored
@ -74747,15 +74747,13 @@ exports.setUpGraalVMDevBuild = setUpGraalVMDevBuild;
|
|||||||
function setUpGraalVMRelease(gdsToken, version, javaVersion) {
|
function setUpGraalVMRelease(gdsToken, version, javaVersion) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const isEE = gdsToken.length > 0;
|
const isEE = gdsToken.length > 0;
|
||||||
const graalVMIdentifier = determineGraalVMIdentifier(isEE, version, javaVersion);
|
|
||||||
const toolName = determineToolName(isEE, javaVersion);
|
const toolName = determineToolName(isEE, javaVersion);
|
||||||
let downloader;
|
let downloader;
|
||||||
if (isEE) {
|
if (isEE) {
|
||||||
downloader = () => __awaiter(this, void 0, void 0, function* () { return gds_1.downloadGraalVMEE(gdsToken, version, javaVersion); });
|
downloader = () => __awaiter(this, void 0, void 0, function* () { return gds_1.downloadGraalVMEE(gdsToken, version, javaVersion); });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`;
|
downloader = () => __awaiter(this, void 0, void 0, function* () { return downloadGraalVMCE(version, javaVersion); });
|
||||||
downloader = () => __awaiter(this, void 0, void 0, function* () { return tool_cache_1.downloadTool(downloadUrl); });
|
|
||||||
}
|
}
|
||||||
return utils_1.downloadExtractAndCacheJDK(downloader, toolName, version);
|
return utils_1.downloadExtractAndCacheJDK(downloader, toolName, version);
|
||||||
});
|
});
|
||||||
@ -74767,6 +74765,22 @@ function determineGraalVMIdentifier(isEE, version, javaVersion) {
|
|||||||
function determineToolName(isEE, javaVersion) {
|
function determineToolName(isEE, javaVersion) {
|
||||||
return `graalvm-${isEE ? 'ee' : 'ce'}-java${javaVersion}-${c.GRAALVM_PLATFORM}`;
|
return `graalvm-${isEE ? 'ee' : 'ce'}-java${javaVersion}-${c.GRAALVM_PLATFORM}`;
|
||||||
}
|
}
|
||||||
|
function downloadGraalVMCE(version, javaVersion) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const graalVMIdentifier = determineGraalVMIdentifier(false, version, javaVersion);
|
||||||
|
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`;
|
||||||
|
try {
|
||||||
|
return yield tool_cache_1.downloadTool(downloadUrl);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (error instanceof Error && error.message.includes('404')) {
|
||||||
|
// Not Found
|
||||||
|
throw new Error(`Failed to download ${graalVMIdentifier}. Are you sure version: '${version}' and javaVersion: '${javaVersion}' are correct?`);
|
||||||
|
}
|
||||||
|
throw new Error(`Failed to download ${graalVMIdentifier} (error: ${error}).`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -63,18 +63,12 @@ export async function setUpGraalVMRelease(
|
|||||||
javaVersion: string
|
javaVersion: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const isEE = gdsToken.length > 0
|
const isEE = gdsToken.length > 0
|
||||||
const graalVMIdentifier = determineGraalVMIdentifier(
|
|
||||||
isEE,
|
|
||||||
version,
|
|
||||||
javaVersion
|
|
||||||
)
|
|
||||||
const toolName = determineToolName(isEE, javaVersion)
|
const toolName = determineToolName(isEE, javaVersion)
|
||||||
let downloader: () => Promise<string>
|
let downloader: () => Promise<string>
|
||||||
if (isEE) {
|
if (isEE) {
|
||||||
downloader = async () => downloadGraalVMEE(gdsToken, version, javaVersion)
|
downloader = async () => downloadGraalVMEE(gdsToken, version, javaVersion)
|
||||||
} else {
|
} else {
|
||||||
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`
|
downloader = async () => downloadGraalVMCE(version, javaVersion)
|
||||||
downloader = async () => downloadTool(downloadUrl)
|
|
||||||
}
|
}
|
||||||
return downloadExtractAndCacheJDK(downloader, toolName, version)
|
return downloadExtractAndCacheJDK(downloader, toolName, version)
|
||||||
}
|
}
|
||||||
@ -94,3 +88,28 @@ function determineToolName(isEE: boolean, javaVersion: string): string {
|
|||||||
c.GRAALVM_PLATFORM
|
c.GRAALVM_PLATFORM
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadGraalVMCE(
|
||||||
|
version: string,
|
||||||
|
javaVersion: string
|
||||||
|
): Promise<string> {
|
||||||
|
const graalVMIdentifier = determineGraalVMIdentifier(
|
||||||
|
false,
|
||||||
|
version,
|
||||||
|
javaVersion
|
||||||
|
)
|
||||||
|
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`
|
||||||
|
try {
|
||||||
|
return await downloadTool(downloadUrl)
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error && error.message.includes('404')) {
|
||||||
|
// Not Found
|
||||||
|
throw new Error(
|
||||||
|
`Failed to download ${graalVMIdentifier}. Are you sure version: '${version}' and javaVersion: '${javaVersion}' are correct?`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`Failed to download ${graalVMIdentifier} (error: ${error}).`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user