fix error handling

This commit is contained in:
mahabaleshwars 2025-04-04 08:55:02 +05:30
parent 52f4f817a5
commit a2a22eb21b
2 changed files with 25 additions and 21 deletions

21
dist/setup/index.js vendored
View File

@ -97476,25 +97476,23 @@ function getManifest() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const repoManifest = yield getManifestFromRepo(); const repoManifest = yield getManifestFromRepo();
core.debug(`Received repo manifest: ${JSON.stringify(repoManifest)}`);
if (Array.isArray(repoManifest) && if (Array.isArray(repoManifest) &&
repoManifest.length && repoManifest.length &&
repoManifest.every(isIToolRelease)) { repoManifest.every(isIToolRelease)) {
core.debug('Repo manifest is valid and contains IToolRelease items.');
return repoManifest; return repoManifest;
} }
else { else {
core.debug('Repo manifest is invalid or does not contain IToolRelease items.'); throw new Error('The repository manifest is invalid or does not include any valid tool release (IToolRelease) entries.');
} }
} }
catch (err) { catch (err) {
core.debug('Fetching the manifest via the API failed.'); core.error('Fetching the manifest via the API failed.');
if (err instanceof Error) { if (err instanceof Error) {
core.debug(`Error message: ${err.message}`); core.debug(`Error message: ${err.message}`);
core.debug(`Error stack: ${err.stack}`); core.debug(`Error stack: ${err.stack}`);
} }
else { else {
core.debug('Error is not an instance of Error. It might be something else.'); core.error('Error is not an instance of Error. It might be something else.');
} }
} }
return yield getManifestFromURL(); return yield getManifestFromURL();
@ -97502,17 +97500,17 @@ function getManifest() {
} }
exports.getManifest = getManifest; exports.getManifest = getManifest;
function getManifestFromRepo() { function getManifestFromRepo() {
core.debug(`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`); core.info(`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`);
return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH); return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
} }
exports.getManifestFromRepo = getManifestFromRepo; exports.getManifestFromRepo = getManifestFromRepo;
function getManifestFromURL() { function getManifestFromURL() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.debug('Falling back to fetching the manifest using raw URL.'); core.info('Falling back to fetching the manifest using raw URL.');
const http = new httpm.HttpClient('tool-cache'); const http = new httpm.HttpClient('tool-cache');
const response = yield http.getJson(exports.MANIFEST_URL); const response = yield http.getJson(exports.MANIFEST_URL);
if (!response.result) { if (!response.result) {
throw new Error(`Unable to get manifest from ${exports.MANIFEST_URL}`); throw new Error(`Unable to get manifest from ${exports.MANIFEST_URL}. HTTP status: ${response.statusCode}`);
} }
return response.result; return response.result;
}); });
@ -97543,6 +97541,9 @@ function installPython(workingDirectory) {
} }
function installCpythonFromRelease(release) { function installCpythonFromRelease(release) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!release.files || release.files.length === 0) {
throw new Error('No files found in the release to download.');
}
const downloadUrl = release.files[0].download_url; const downloadUrl = release.files[0].download_url;
core.info(`Download from "${downloadUrl}"`); core.info(`Download from "${downloadUrl}"`);
let pythonPath = ''; let pythonPath = '';
@ -97564,10 +97565,10 @@ function installCpythonFromRelease(release) {
if (err instanceof tc.HTTPError) { if (err instanceof tc.HTTPError) {
// Rate limit? // Rate limit?
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) { if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`); core.error(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
} }
else { else {
core.info(err.message); core.error(err.message);
} }
if (err.stack) { if (err.stack) {
core.debug(err.stack); core.debug(err.stack);

View File

@ -53,27 +53,25 @@ function isIToolRelease(obj: any): obj is IToolRelease {
export async function getManifest(): Promise<tc.IToolRelease[]> { export async function getManifest(): Promise<tc.IToolRelease[]> {
try { try {
const repoManifest = await getManifestFromRepo(); const repoManifest = await getManifestFromRepo();
core.debug(`Received repo manifest: ${JSON.stringify(repoManifest)}`);
if ( if (
Array.isArray(repoManifest) && Array.isArray(repoManifest) &&
repoManifest.length && repoManifest.length &&
repoManifest.every(isIToolRelease) repoManifest.every(isIToolRelease)
) { ) {
core.debug('Repo manifest is valid and contains IToolRelease items.');
return repoManifest; return repoManifest;
} else { } else {
core.debug( throw new Error(
'Repo manifest is invalid or does not contain IToolRelease items.' 'The repository manifest is invalid or does not include any valid tool release (IToolRelease) entries.'
); );
} }
} catch (err) { } catch (err) {
core.debug('Fetching the manifest via the API failed.'); core.error('Fetching the manifest via the API failed.');
if (err instanceof Error) { if (err instanceof Error) {
core.debug(`Error message: ${err.message}`); core.debug(`Error message: ${err.message}`);
core.debug(`Error stack: ${err.stack}`); core.debug(`Error stack: ${err.stack}`);
} else { } else {
core.debug( core.error(
'Error is not an instance of Error. It might be something else.' 'Error is not an instance of Error. It might be something else.'
); );
} }
@ -82,7 +80,7 @@ export async function getManifest(): Promise<tc.IToolRelease[]> {
} }
export function getManifestFromRepo(): Promise<tc.IToolRelease[]> { export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
core.debug( core.info(
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}` `Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`
); );
return tc.getManifestFromRepo( return tc.getManifestFromRepo(
@ -94,12 +92,14 @@ export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
} }
export async function getManifestFromURL(): Promise<tc.IToolRelease[]> { export async function getManifestFromURL(): Promise<tc.IToolRelease[]> {
core.debug('Falling back to fetching the manifest using raw URL.'); core.info('Falling back to fetching the manifest using raw URL.');
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache'); const http: httpm.HttpClient = new httpm.HttpClient('tool-cache');
const response = await http.getJson<tc.IToolRelease[]>(MANIFEST_URL); const response = await http.getJson<tc.IToolRelease[]>(MANIFEST_URL);
if (!response.result) { if (!response.result) {
throw new Error(`Unable to get manifest from ${MANIFEST_URL}`); throw new Error(
`Unable to get manifest from ${MANIFEST_URL}. HTTP status: ${response.statusCode}`
);
} }
return response.result; return response.result;
} }
@ -130,6 +130,9 @@ async function installPython(workingDirectory: string) {
} }
export async function installCpythonFromRelease(release: tc.IToolRelease) { export async function installCpythonFromRelease(release: tc.IToolRelease) {
if (!release.files || release.files.length === 0) {
throw new Error('No files found in the release to download.');
}
const downloadUrl = release.files[0].download_url; const downloadUrl = release.files[0].download_url;
core.info(`Download from "${downloadUrl}"`); core.info(`Download from "${downloadUrl}"`);
@ -151,11 +154,11 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
if (err instanceof tc.HTTPError) { if (err instanceof tc.HTTPError) {
// Rate limit? // Rate limit?
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) { if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
core.info( core.error(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded` `Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
); );
} else { } else {
core.info(err.message); core.error(err.message);
} }
if (err.stack) { if (err.stack) {
core.debug(err.stack); core.debug(err.stack);