mirror of
https://github.com/actions/setup-java.git
synced 2025-11-05 17:00:54 +00:00
enhance error logging and implement retry
This commit is contained in:
parent
ead9eaa3cf
commit
ff566a4e9a
3 changed files with 175 additions and 56 deletions
108
dist/setup/index.js
vendored
108
dist/setup/index.js
vendored
|
|
@ -129856,6 +129856,7 @@ class JavaBase {
|
||||||
this.checkLatest = installerOptions.checkLatest;
|
this.checkLatest = installerOptions.checkLatest;
|
||||||
}
|
}
|
||||||
setupJava() {
|
setupJava() {
|
||||||
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let foundJava = this.findInToolcache();
|
let foundJava = this.findInToolcache();
|
||||||
if (foundJava && !this.checkLatest) {
|
if (foundJava && !this.checkLatest) {
|
||||||
|
|
@ -129863,40 +129864,95 @@ class JavaBase {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.info('Trying to resolve the latest version from remote');
|
core.info('Trying to resolve the latest version from remote');
|
||||||
try {
|
let retries = 4;
|
||||||
const javaRelease = yield this.findPackageForDownload(this.version);
|
const retryableCodes = [
|
||||||
core.info(`Resolved latest version as ${javaRelease.version}`);
|
'ETIMEDOUT',
|
||||||
if ((foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) === javaRelease.version) {
|
'ECONNRESET',
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
'ENOTFOUND',
|
||||||
}
|
'ECONNREFUSED'
|
||||||
else {
|
];
|
||||||
core.info('Trying to download...');
|
while (retries > 0) {
|
||||||
foundJava = yield this.downloadTool(javaRelease);
|
try {
|
||||||
core.info(`Java ${foundJava.version} was downloaded`);
|
// Clear console timers before each attempt to prevent conflicts
|
||||||
}
|
if (retries < 4 && core.isDebug()) {
|
||||||
}
|
const consoleAny = console;
|
||||||
catch (error) {
|
(_b = (_a = consoleAny._times) === null || _a === void 0 ? void 0 : _a.clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||||
if (error instanceof tc.HTTPError) {
|
|
||||||
if (error.httpStatusCode === 403) {
|
|
||||||
core.error('HTTP 403: Permission denied or access restricted.');
|
|
||||||
}
|
}
|
||||||
else if (error.httpStatusCode === 429) {
|
const javaRelease = yield this.findPackageForDownload(this.version);
|
||||||
core.warning('HTTP 429: Rate limit exceeded. Please retry later.');
|
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||||
|
if ((foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) === javaRelease.version) {
|
||||||
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.error(`HTTP ${error.httpStatusCode}: ${error.message}`);
|
core.info('Trying to download...');
|
||||||
|
foundJava = yield this.downloadTool(javaRelease);
|
||||||
|
core.info(`Java ${foundJava.version} was downloaded`);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
catch (error) {
|
||||||
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
retries--;
|
||||||
core.error(`Java setup failed due to network issue or timeout: ${message}`);
|
// Check if error is retryable (including aggregate errors)
|
||||||
|
const isRetryable = (error instanceof tc.HTTPError &&
|
||||||
|
error.httpStatusCode &&
|
||||||
|
[429, 502, 503, 504].includes(error.httpStatusCode)) ||
|
||||||
|
retryableCodes.includes(error === null || error === void 0 ? void 0 : error.code) ||
|
||||||
|
((error === null || error === void 0 ? void 0 : error.errors) &&
|
||||||
|
Array.isArray(error.errors) &&
|
||||||
|
error.errors.some((err) => retryableCodes.includes(err === null || err === void 0 ? void 0 : err.code)));
|
||||||
|
if (retries > 0 && isRetryable) {
|
||||||
|
core.debug(`Attempt failed due to network or timeout issues, initiating retry... (${retries} attempts left)`);
|
||||||
|
yield new Promise(r => setTimeout(r, 2000));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (error instanceof tc.HTTPError) {
|
||||||
|
if (error.httpStatusCode === 403) {
|
||||||
|
core.error('HTTP 403: Permission denied or access restricted.');
|
||||||
|
}
|
||||||
|
else if (error.httpStatusCode === 429) {
|
||||||
|
core.warning('HTTP 429: Rate limit exceeded. Please retry later.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.error(`HTTP ${error.httpStatusCode}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (error && error.errors && Array.isArray(error.errors)) {
|
||||||
|
core.error(`Java setup failed due to network or configuration error(s)`);
|
||||||
|
if (error instanceof Error && error.stack) {
|
||||||
|
core.debug(error.stack);
|
||||||
|
}
|
||||||
|
for (const err of error.errors) {
|
||||||
|
const endpoint = (err === null || err === void 0 ? void 0 : err.address) || (err === null || err === void 0 ? void 0 : err.hostname) || '';
|
||||||
|
const port = (err === null || err === void 0 ? void 0 : err.port) ? `:${err.port}` : '';
|
||||||
|
const message = (err === null || err === void 0 ? void 0 : err.message) || 'Aggregate error';
|
||||||
|
const logMessage = `${message}${!message.includes(endpoint) ? ` ${endpoint}${port}` : ''}${err.localAddress && err.localPort ? ` - Local (${err.localAddress}:${err.localPort})` : ''}`;
|
||||||
|
core.error(logMessage);
|
||||||
|
core.debug(`${err.stack || err.message}`);
|
||||||
|
Object.entries(err).forEach(([key, value]) => {
|
||||||
|
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
||||||
|
core.error(`Java setup process failed due to: ${message}`);
|
||||||
|
if (typeof (error === null || error === void 0 ? void 0 : error.code) === 'string') {
|
||||||
|
core.debug(error.stack);
|
||||||
|
}
|
||||||
|
const errorDetails = Object.assign({ name: error.name, message: error.message }, Object.getOwnPropertyNames(error)
|
||||||
|
.filter(prop => !['name', 'message', 'stack'].includes(prop))
|
||||||
|
.reduce((acc, prop) => (Object.assign(Object.assign({}, acc), { [prop]: error[prop] })), {}));
|
||||||
|
Object.entries(errorDetails).forEach(([key, value]) => {
|
||||||
|
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
if (error instanceof Error && error.stack) {
|
|
||||||
core.debug(error.stack);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!foundJava) {
|
||||||
|
throw new Error('Failed to resolve Java version');
|
||||||
|
}
|
||||||
// JDK folder may contain postfix "Contents/Home" on macOS
|
// JDK folder may contain postfix "Contents/Home" on macOS
|
||||||
const macOSPostfixPath = path_1.default.join(foundJava.path, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
|
const macOSPostfixPath = path_1.default.join(foundJava.path, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
|
||||||
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
||||||
|
|
|
||||||
1
package-lock.json
generated
1
package-lock.json
generated
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "setup-java",
|
"name": "setup-java",
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
|
|
|
||||||
|
|
@ -51,39 +51,103 @@ export abstract class JavaBase {
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
} else {
|
} else {
|
||||||
core.info('Trying to resolve the latest version from remote');
|
core.info('Trying to resolve the latest version from remote');
|
||||||
try {
|
let retries = 4;
|
||||||
const javaRelease = await this.findPackageForDownload(this.version);
|
const retryableCodes = [
|
||||||
core.info(`Resolved latest version as ${javaRelease.version}`);
|
'ETIMEDOUT',
|
||||||
if (foundJava?.version === javaRelease.version) {
|
'ECONNRESET',
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
'ENOTFOUND',
|
||||||
} else {
|
'ECONNREFUSED'
|
||||||
core.info('Trying to download...');
|
];
|
||||||
foundJava = await this.downloadTool(javaRelease);
|
while (retries > 0) {
|
||||||
core.info(`Java ${foundJava.version} was downloaded`);
|
try {
|
||||||
}
|
// Clear console timers before each attempt to prevent conflicts
|
||||||
} catch (error: any) {
|
if (retries < 4 && core.isDebug()) {
|
||||||
if (error instanceof tc.HTTPError) {
|
const consoleAny = console as any;
|
||||||
if (error.httpStatusCode === 403) {
|
consoleAny._times?.clear?.();
|
||||||
core.error('HTTP 403: Permission denied or access restricted.');
|
|
||||||
} else if (error.httpStatusCode === 429) {
|
|
||||||
core.warning('HTTP 429: Rate limit exceeded. Please retry later.');
|
|
||||||
} else {
|
|
||||||
core.error(`HTTP ${error.httpStatusCode}: ${error.message}`);
|
|
||||||
}
|
}
|
||||||
} else {
|
const javaRelease = await this.findPackageForDownload(this.version);
|
||||||
const message =
|
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||||
error instanceof Error ? error.message : JSON.stringify(error);
|
if (foundJava?.version === javaRelease.version) {
|
||||||
core.error(
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
`Java setup failed due to network issue or timeout: ${message}`
|
} else {
|
||||||
);
|
core.info('Trying to download...');
|
||||||
|
foundJava = await this.downloadTool(javaRelease);
|
||||||
|
core.info(`Java ${foundJava.version} was downloaded`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (error: any) {
|
||||||
|
retries--;
|
||||||
|
// Check if error is retryable (including aggregate errors)
|
||||||
|
const isRetryable =
|
||||||
|
(error instanceof tc.HTTPError &&
|
||||||
|
error.httpStatusCode &&
|
||||||
|
[429, 502, 503, 504].includes(error.httpStatusCode)) ||
|
||||||
|
retryableCodes.includes(error?.code) ||
|
||||||
|
(error?.errors &&
|
||||||
|
Array.isArray(error.errors) &&
|
||||||
|
error.errors.some((err: any) =>
|
||||||
|
retryableCodes.includes(err?.code)
|
||||||
|
));
|
||||||
|
if (retries > 0 && isRetryable) {
|
||||||
|
core.debug(
|
||||||
|
`Attempt failed due to network or timeout issues, initiating retry... (${retries} attempts left)`
|
||||||
|
);
|
||||||
|
await new Promise(r => setTimeout(r, 2000));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (error instanceof tc.HTTPError) {
|
||||||
|
if (error.httpStatusCode === 403) {
|
||||||
|
core.error('HTTP 403: Permission denied or access restricted.');
|
||||||
|
} else if (error.httpStatusCode === 429) {
|
||||||
|
core.warning(
|
||||||
|
'HTTP 429: Rate limit exceeded. Please retry later.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
core.error(`HTTP ${error.httpStatusCode}: ${error.message}`);
|
||||||
|
}
|
||||||
|
} else if (error && error.errors && Array.isArray(error.errors)) {
|
||||||
|
core.error(
|
||||||
|
`Java setup failed due to network or configuration error(s)`
|
||||||
|
);
|
||||||
|
if (error instanceof Error && error.stack) {
|
||||||
|
core.debug(error.stack);
|
||||||
|
}
|
||||||
|
for (const err of error.errors) {
|
||||||
|
const endpoint = err?.address || err?.hostname || '';
|
||||||
|
const port = err?.port ? `:${err.port}` : '';
|
||||||
|
const message = err?.message || 'Aggregate error';
|
||||||
|
const logMessage = `${message}${!message.includes(endpoint) ? ` ${endpoint}${port}` : ''}${err.localAddress && err.localPort ? ` - Local (${err.localAddress}:${err.localPort})` : ''}`;
|
||||||
|
core.error(logMessage);
|
||||||
|
core.debug(`${err.stack || err.message}`);
|
||||||
|
Object.entries(err).forEach(([key, value]) => {
|
||||||
|
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const message =
|
||||||
|
error instanceof Error ? error.message : JSON.stringify(error);
|
||||||
|
core.error(`Java setup process failed due to: ${message}`);
|
||||||
|
if (typeof error?.code === 'string') {
|
||||||
|
core.debug(error.stack);
|
||||||
|
}
|
||||||
|
const errorDetails = {
|
||||||
|
name: error.name,
|
||||||
|
message: error.message,
|
||||||
|
...Object.getOwnPropertyNames(error)
|
||||||
|
.filter(prop => !['name', 'message', 'stack'].includes(prop))
|
||||||
|
.reduce((acc, prop) => ({...acc, [prop]: error[prop]}), {})
|
||||||
|
};
|
||||||
|
Object.entries(errorDetails).forEach(([key, value]) => {
|
||||||
|
core.debug(`"${key}": ${JSON.stringify(value)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
if (error instanceof Error && error.stack) {
|
|
||||||
core.debug(error.stack);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!foundJava) {
|
||||||
|
throw new Error('Failed to resolve Java version');
|
||||||
|
}
|
||||||
// JDK folder may contain postfix "Contents/Home" on macOS
|
// JDK folder may contain postfix "Contents/Home" on macOS
|
||||||
const macOSPostfixPath = path.join(
|
const macOSPostfixPath = path.join(
|
||||||
foundJava.path,
|
foundJava.path,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue