From 46a44325a70909a4ce3d6abe2f218e4dde76e2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgowridurgad=E2=80=9D?= <“hgowridurgad@github.com> Date: Fri, 25 Apr 2025 12:42:02 +0530 Subject: [PATCH 1/2] error handling --- dist/setup/index.js | 45 ++++++++++++++++++----- src/distributions/base-installer.ts | 55 ++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 08107f095..7939076e2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -128793,15 +128793,44 @@ class JavaBase { } else { core.info('Trying to resolve the latest version from remote'); - const javaRelease = yield this.findPackageForDownload(this.version); - 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`); + try { + const javaRelease = yield this.findPackageForDownload(this.version); + 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 { + core.info('Trying to download...'); + try { + foundJava = yield this.downloadTool(javaRelease); + core.info(`Java ${foundJava.version} was downloaded`); + } + catch (downloadError) { + core.error('Failed to download Java. Please check your network connection or the provided version.'); + core.error(`Error details: ${downloadError.message}`); + throw downloadError; + } + } } - else { - core.info('Trying to download...'); - foundJava = yield this.downloadTool(javaRelease); - core.info(`Java ${foundJava.version} was downloaded`); + catch (resolveError) { + if (resolveError instanceof tc.HTTPError && + resolveError.httpStatusCode === 403) { + core.error(`Received HTTP 403: Permission denied or restricted access.`); + } + else if (resolveError instanceof tc.HTTPError && + resolveError.httpStatusCode === 429) { + core.warning(`Received HTTP 429: Rate limit exceeded. Try again later.`); + } + else { + const message = resolveError instanceof Error + ? resolveError.message + : JSON.stringify(resolveError); + core.error(`Failed to set up Java due to a network issue or timeout: ${message}`); + } + if (resolveError instanceof Error && resolveError.stack) { + core.debug(resolveError.stack); + } + throw resolveError; } } // JDK folder may contain postfix "Contents/Home" on macOS diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 258ac9f4c..7610884f1 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -51,14 +51,53 @@ export abstract class JavaBase { core.info(`Resolved Java ${foundJava.version} from tool-cache`); } else { core.info('Trying to resolve the latest version from remote'); - const javaRelease = await this.findPackageForDownload(this.version); - core.info(`Resolved latest version as ${javaRelease.version}`); - if (foundJava?.version === javaRelease.version) { - core.info(`Resolved Java ${foundJava.version} from tool-cache`); - } else { - core.info('Trying to download...'); - foundJava = await this.downloadTool(javaRelease); - core.info(`Java ${foundJava.version} was downloaded`); + try { + const javaRelease = await this.findPackageForDownload(this.version); + core.info(`Resolved latest version as ${javaRelease.version}`); + if (foundJava?.version === javaRelease.version) { + core.info(`Resolved Java ${foundJava.version} from tool-cache`); + } else { + core.info('Trying to download...'); + try { + foundJava = await this.downloadTool(javaRelease); + core.info(`Java ${foundJava.version} was downloaded`); + } catch (downloadError: any) { + core.error( + 'Failed to download Java. Please check your network connection or the provided version.' + ); + core.error(`Error details: ${downloadError.message}`); + throw downloadError; + } + } + } catch (resolveError: any) { + if ( + resolveError instanceof tc.HTTPError && + resolveError.httpStatusCode === 403 + ) { + core.error( + `Received HTTP 403: Permission denied or restricted access.` + ); + } else if ( + resolveError instanceof tc.HTTPError && + resolveError.httpStatusCode === 429 + ) { + core.warning( + `Received HTTP 429: Rate limit exceeded. Try again later.` + ); + } else { + const message = + resolveError instanceof Error + ? resolveError.message + : JSON.stringify(resolveError); + core.error( + `Failed to set up Java due to a network issue or timeout: ${message}` + ); + } + if (resolveError instanceof Error && resolveError.stack) { + core.debug(resolveError.stack); + } + + throw resolveError; } } From 8be1e72903d3dc8ef04d9d95bb268da05cc6027f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgowridurgad=E2=80=9D?= <“hgowridurgad@github.com> Date: Wed, 4 Jun 2025 15:09:45 +0530 Subject: [PATCH 2/2] commit --- dist/setup/index.js | 30 +++++++++----------------- src/distributions/base-installer.ts | 33 +++++++++-------------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 7939076e2..391e4d6a3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -128801,36 +128801,26 @@ class JavaBase { } else { core.info('Trying to download...'); - try { - foundJava = yield this.downloadTool(javaRelease); - core.info(`Java ${foundJava.version} was downloaded`); - } - catch (downloadError) { - core.error('Failed to download Java. Please check your network connection or the provided version.'); - core.error(`Error details: ${downloadError.message}`); - throw downloadError; - } + foundJava = yield this.downloadTool(javaRelease); + core.info(`Java ${foundJava.version} was downloaded`); } } - catch (resolveError) { - if (resolveError instanceof tc.HTTPError && - resolveError.httpStatusCode === 403) { + catch (error) { + if (error instanceof tc.HTTPError && error.httpStatusCode === 403) { core.error(`Received HTTP 403: Permission denied or restricted access.`); } - else if (resolveError instanceof tc.HTTPError && - resolveError.httpStatusCode === 429) { + else if (error instanceof tc.HTTPError && + error.httpStatusCode === 429) { core.warning(`Received HTTP 429: Rate limit exceeded. Try again later.`); } else { - const message = resolveError instanceof Error - ? resolveError.message - : JSON.stringify(resolveError); + const message = error instanceof Error ? error.message : JSON.stringify(error); core.error(`Failed to set up Java due to a network issue or timeout: ${message}`); } - if (resolveError instanceof Error && resolveError.stack) { - core.debug(resolveError.stack); + if (error instanceof Error && error.stack) { + core.debug(error.stack); } - throw resolveError; + throw error; } } // JDK folder may contain postfix "Contents/Home" on macOS diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 7610884f1..4385c9bc0 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -58,46 +58,33 @@ export abstract class JavaBase { core.info(`Resolved Java ${foundJava.version} from tool-cache`); } else { core.info('Trying to download...'); - try { - foundJava = await this.downloadTool(javaRelease); - core.info(`Java ${foundJava.version} was downloaded`); - } catch (downloadError: any) { - core.error( - 'Failed to download Java. Please check your network connection or the provided version.' - ); - core.error(`Error details: ${downloadError.message}`); - throw downloadError; - } + foundJava = await this.downloadTool(javaRelease); + core.info(`Java ${foundJava.version} was downloaded`); } - } catch (resolveError: any) { - if ( - resolveError instanceof tc.HTTPError && - resolveError.httpStatusCode === 403 - ) { + } catch (error: any) { + if (error instanceof tc.HTTPError && error.httpStatusCode === 403) { core.error( `Received HTTP 403: Permission denied or restricted access.` ); } else if ( - resolveError instanceof tc.HTTPError && - resolveError.httpStatusCode === 429 + error instanceof tc.HTTPError && + error.httpStatusCode === 429 ) { core.warning( `Received HTTP 429: Rate limit exceeded. Try again later.` ); } else { const message = - resolveError instanceof Error - ? resolveError.message - : JSON.stringify(resolveError); + error instanceof Error ? error.message : JSON.stringify(error); core.error( `Failed to set up Java due to a network issue or timeout: ${message}` ); } - if (resolveError instanceof Error && resolveError.stack) { - core.debug(resolveError.stack); + if (error instanceof Error && error.stack) { + core.debug(error.stack); } - throw resolveError; + throw error; } }