From a25c57cebee462bc9354608581f6151e3899544c Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Mon, 22 Sep 2025 13:20:16 +0200 Subject: [PATCH] Wrap API call to provide better error message --- lib/analyze-action.js | 28 +++++++++++++++++----------- lib/init-action-post.js | 28 +++++++++++++++++----------- lib/init-action.js | 28 +++++++++++++++++----------- lib/upload-lib.js | 28 +++++++++++++++++----------- lib/upload-sarif-action.js | 28 +++++++++++++++++----------- src/setup-codeql.ts | 36 ++++++++++++++++++++---------------- 6 files changed, 105 insertions(+), 71 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 185d5154c..4a11b910f 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -92521,18 +92521,24 @@ async function getNightlyToolsUrl(logger) { CODEQL_VERSION_ZSTD_BUNDLE, zstdAvailability.available ) ? "zstd" : "gzip"; - const release3 = await getApiClient().rest.repos.listReleases({ - owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, - repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, - per_page: 1, - page: 1, - prerelease: true - }); - const latestRelease = release3.data[0]; - if (!latestRelease) { - throw new Error("Could not find latest nightly release."); + try { + const release3 = await getApiClient().rest.repos.listReleases({ + owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, + repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, + per_page: 1, + page: 1, + prerelease: true + }); + const latestRelease = release3.data[0]; + if (!latestRelease) { + throw new Error("Could not find the latest nightly release."); + } + return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; + } catch (e) { + throw new Error( + `Failed to retrieve the latest nightly release: ${wrapError(e)}` + ); } - return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; } // src/tracer-config.ts diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 601977910..ccb4b8bec 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -130464,18 +130464,24 @@ async function getNightlyToolsUrl(logger) { CODEQL_VERSION_ZSTD_BUNDLE, zstdAvailability.available ) ? "zstd" : "gzip"; - const release3 = await getApiClient().rest.repos.listReleases({ - owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, - repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, - per_page: 1, - page: 1, - prerelease: true - }); - const latestRelease = release3.data[0]; - if (!latestRelease) { - throw new Error("Could not find latest nightly release."); + try { + const release3 = await getApiClient().rest.repos.listReleases({ + owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, + repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, + per_page: 1, + page: 1, + prerelease: true + }); + const latestRelease = release3.data[0]; + if (!latestRelease) { + throw new Error("Could not find the latest nightly release."); + } + return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; + } catch (e) { + throw new Error( + `Failed to retrieve the latest nightly release: ${wrapError(e)}` + ); } - return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; } // src/tracer-config.ts diff --git a/lib/init-action.js b/lib/init-action.js index 63d21aded..a5e8991d7 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -89138,18 +89138,24 @@ async function getNightlyToolsUrl(logger) { CODEQL_VERSION_ZSTD_BUNDLE, zstdAvailability.available ) ? "zstd" : "gzip"; - const release3 = await getApiClient().rest.repos.listReleases({ - owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, - repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, - per_page: 1, - page: 1, - prerelease: true - }); - const latestRelease = release3.data[0]; - if (!latestRelease) { - throw new Error("Could not find latest nightly release."); + try { + const release3 = await getApiClient().rest.repos.listReleases({ + owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, + repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, + per_page: 1, + page: 1, + prerelease: true + }); + const latestRelease = release3.data[0]; + if (!latestRelease) { + throw new Error("Could not find the latest nightly release."); + } + return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; + } catch (e) { + throw new Error( + `Failed to retrieve the latest nightly release: ${wrapError(e)}` + ); } - return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; } // src/tracer-config.ts diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 19a978adf..3d3baed6f 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -90292,18 +90292,24 @@ async function getNightlyToolsUrl(logger) { CODEQL_VERSION_ZSTD_BUNDLE, zstdAvailability.available ) ? "zstd" : "gzip"; - const release = await getApiClient().rest.repos.listReleases({ - owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, - repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, - per_page: 1, - page: 1, - prerelease: true - }); - const latestRelease = release.data[0]; - if (!latestRelease) { - throw new Error("Could not find latest nightly release."); + try { + const release = await getApiClient().rest.repos.listReleases({ + owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, + repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, + per_page: 1, + page: 1, + prerelease: true + }); + const latestRelease = release.data[0]; + if (!latestRelease) { + throw new Error("Could not find the latest nightly release."); + } + return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; + } catch (e) { + throw new Error( + `Failed to retrieve the latest nightly release: ${wrapError(e)}` + ); } - return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; } // src/tracer-config.ts diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index ff240c273..5c266dcce 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -90993,18 +90993,24 @@ async function getNightlyToolsUrl(logger) { CODEQL_VERSION_ZSTD_BUNDLE, zstdAvailability.available ) ? "zstd" : "gzip"; - const release3 = await getApiClient().rest.repos.listReleases({ - owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, - repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, - per_page: 1, - page: 1, - prerelease: true - }); - const latestRelease = release3.data[0]; - if (!latestRelease) { - throw new Error("Could not find latest nightly release."); + try { + const release3 = await getApiClient().rest.repos.listReleases({ + owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, + repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, + per_page: 1, + page: 1, + prerelease: true + }); + const latestRelease = release3.data[0]; + if (!latestRelease) { + throw new Error("Could not find the latest nightly release."); + } + return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; + } catch (e) { + throw new Error( + `Failed to retrieve the latest nightly release: ${wrapError(e)}` + ); } - return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; } // src/tracer-config.ts diff --git a/src/setup-codeql.ts b/src/setup-codeql.ts index ad09d8d60..a9b76ac4d 100644 --- a/src/setup-codeql.ts +++ b/src/setup-codeql.ts @@ -799,21 +799,25 @@ async function getNightlyToolsUrl(logger: Logger) { ? "zstd" : "gzip"; - // Since nightlies are prereleases, we can't just download the latest release - // on the repository. So instead we need to find the latest pre-release - // version and construct the download URL from that. - const release = await api.getApiClient().rest.repos.listReleases({ - owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, - repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, - per_page: 1, - page: 1, - prerelease: true, - }); - - const latestRelease = release.data[0]; - if (!latestRelease) { - throw new Error("Could not find latest nightly release."); + try { + // Since nightlies are prereleases, we can't just download the latest release + // on the repository. So instead we need to find the latest pre-release + // version and construct the download URL from that. + const release = await api.getApiClient().rest.repos.listReleases({ + owner: CODEQL_NIGHTLIES_REPOSITORY_OWNER, + repo: CODEQL_NIGHTLIES_REPOSITORY_NAME, + per_page: 1, + page: 1, + prerelease: true, + }); + const latestRelease = release.data[0]; + if (!latestRelease) { + throw new Error("Could not find the latest nightly release."); + } + return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; + } catch (e) { + throw new Error( + `Failed to retrieve the latest nightly release: ${util.wrapError(e)}`, + ); } - - return `https://github.com/${CODEQL_NIGHTLIES_REPOSITORY_OWNER}/${CODEQL_NIGHTLIES_REPOSITORY_NAME}/releases/download/${latestRelease.tag_name}/${getCodeQLBundleName(compressionMethod)}`; }