From 7c72e12ecbeb0baf4ce415fd244e36d907037ce0 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 22 Jan 2026 10:46:05 +0000 Subject: [PATCH 01/10] Expand try-catch to cover more of Actions --- lib/analyze-action.js | 4 +- lib/init-action.js | 66 +++++++++++++++------------- lib/setup-codeql-action.js | 40 ++++++++--------- lib/start-proxy-action.js | 2 +- lib/upload-sarif-action.js | 44 +++++++++---------- src/analyze-action.ts | 13 +++--- src/init-action.ts | 89 ++++++++++++++++++++------------------ src/setup-codeql-action.ts | 43 +++++++++--------- src/start-proxy-action.ts | 6 +-- src/upload-sarif-action.ts | 49 +++++++++++---------- 10 files changed, 184 insertions(+), 172 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 1ac83ed0a6..8a00e01cce 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -96343,10 +96343,10 @@ async function run() { let didUploadTrapCaches = false; let dependencyCacheResults; let databaseUploadResults = []; - initializeEnvironment(getActionVersion()); - persistInputs(); const logger = getActionsLogger(); try { + initializeEnvironment(getActionVersion()); + persistInputs(); const statusReportBase = await createStatusReportBase( "finish" /* Analyze */, "starting", diff --git a/lib/init-action.js b/lib/init-action.js index 37656350c6..ae69001c19 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92506,45 +92506,49 @@ async function sendCompletedStatusReport(startedAt, config, configFile, toolsDow async function run() { const startedAt = /* @__PURE__ */ new Date(); const logger = getActionsLogger(); - initializeEnvironment(getActionVersion()); - persistInputs(); + let apiDetails; let config; + let configFile; let codeql; + let features; + let sourceRoot; let toolsDownloadStatusReport; let toolsFeatureFlagsValid; let toolsSource; let toolsVersion; let zstdAvailability; - const apiDetails = { - auth: getRequiredInput("token"), - externalRepoAuth: getOptionalInput("external-repository-token"), - url: getRequiredEnvParam("GITHUB_SERVER_URL"), - apiURL: getRequiredEnvParam("GITHUB_API_URL") - }; - const gitHubVersion = await getGitHubVersion(); - checkGitHubVersionInRange(gitHubVersion, logger); - checkActionVersion(getActionVersion(), gitHubVersion); - const repositoryNwo = getRepositoryNwo(); - const features = new Features( - gitHubVersion, - repositoryNwo, - getTemporaryDirectory(), - logger - ); - const enableRepoProps = await features.getValue( - "use_repository_properties" /* UseRepositoryProperties */ - ); - const repositoryProperties = enableRepoProps ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) : {}; - const jobRunUuid = v4_default(); - logger.info(`Job run UUID is ${jobRunUuid}.`); - core13.exportVariable("JOB_RUN_UUID" /* JOB_RUN_UUID */, jobRunUuid); - core13.exportVariable("CODEQL_ACTION_INIT_HAS_RUN" /* INIT_ACTION_HAS_RUN */, "true"); - const configFile = getOptionalInput("config-file"); - const sourceRoot = path15.resolve( - getRequiredEnvParam("GITHUB_WORKSPACE"), - getOptionalInput("source-root") || "" - ); try { + initializeEnvironment(getActionVersion()); + persistInputs(); + apiDetails = { + auth: getRequiredInput("token"), + externalRepoAuth: getOptionalInput("external-repository-token"), + url: getRequiredEnvParam("GITHUB_SERVER_URL"), + apiURL: getRequiredEnvParam("GITHUB_API_URL") + }; + const gitHubVersion = await getGitHubVersion(); + checkGitHubVersionInRange(gitHubVersion, logger); + checkActionVersion(getActionVersion(), gitHubVersion); + const repositoryNwo = getRepositoryNwo(); + features = new Features( + gitHubVersion, + repositoryNwo, + getTemporaryDirectory(), + logger + ); + const enableRepoProps = await features.getValue( + "use_repository_properties" /* UseRepositoryProperties */ + ); + const repositoryProperties = enableRepoProps ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) : {}; + const jobRunUuid = v4_default(); + logger.info(`Job run UUID is ${jobRunUuid}.`); + core13.exportVariable("JOB_RUN_UUID" /* JOB_RUN_UUID */, jobRunUuid); + core13.exportVariable("CODEQL_ACTION_INIT_HAS_RUN" /* INIT_ACTION_HAS_RUN */, "true"); + configFile = getOptionalInput("config-file"); + sourceRoot = path15.resolve( + getRequiredEnvParam("GITHUB_WORKSPACE"), + getOptionalInput("source-root") || "" + ); let analysisKinds; try { analysisKinds = await getAnalysisKinds(logger); diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 0a9b97198a..0f57e54614 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89864,32 +89864,32 @@ async function sendCompletedStatusReport(startedAt, toolsDownloadStatusReport, t async function run() { const startedAt = /* @__PURE__ */ new Date(); const logger = getActionsLogger(); - initializeEnvironment(getActionVersion()); let codeql; let toolsDownloadStatusReport; let toolsFeatureFlagsValid; let toolsSource; let toolsVersion; - const apiDetails = { - auth: getRequiredInput("token"), - externalRepoAuth: getOptionalInput("external-repository-token"), - url: getRequiredEnvParam("GITHUB_SERVER_URL"), - apiURL: getRequiredEnvParam("GITHUB_API_URL") - }; - const gitHubVersion = await getGitHubVersion(); - checkGitHubVersionInRange(gitHubVersion, logger); - checkActionVersion(getActionVersion(), gitHubVersion); - const repositoryNwo = getRepositoryNwo(); - const features = new Features( - gitHubVersion, - repositoryNwo, - getTemporaryDirectory(), - logger - ); - const jobRunUuid = v4_default(); - logger.info(`Job run UUID is ${jobRunUuid}.`); - core12.exportVariable("JOB_RUN_UUID" /* JOB_RUN_UUID */, jobRunUuid); try { + initializeEnvironment(getActionVersion()); + const apiDetails = { + auth: getRequiredInput("token"), + externalRepoAuth: getOptionalInput("external-repository-token"), + url: getRequiredEnvParam("GITHUB_SERVER_URL"), + apiURL: getRequiredEnvParam("GITHUB_API_URL") + }; + const gitHubVersion = await getGitHubVersion(); + checkGitHubVersionInRange(gitHubVersion, logger); + checkActionVersion(getActionVersion(), gitHubVersion); + const repositoryNwo = getRepositoryNwo(); + const features = new Features( + gitHubVersion, + repositoryNwo, + getTemporaryDirectory(), + logger + ); + const jobRunUuid = v4_default(); + logger.info(`Job run UUID is ${jobRunUuid}.`); + core12.exportVariable("JOB_RUN_UUID" /* JOB_RUN_UUID */, jobRunUuid); const statusReportBase = await createStatusReportBase( "setup-codeql" /* SetupCodeQL */, "starting", diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index f855c5a0a0..4b7f556ec0 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104733,10 +104733,10 @@ async function sendSuccessStatusReport(startedAt, config, registry_types, logger } async function runWrapper() { const startedAt = /* @__PURE__ */ new Date(); - persistInputs(); const logger = getActionsLogger(); let language; try { + persistInputs(); const tempDir = getTemporaryDirectory(); const proxyLogFilePath = path.resolve(tempDir, "proxy.log"); core11.saveState("proxy-log-file", proxyLogFilePath); diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 3d278c11c0..df3c634613 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -94705,29 +94705,29 @@ async function sendSuccessStatusReport(startedAt, uploadStats, logger) { async function run() { const startedAt = /* @__PURE__ */ new Date(); const logger = getActionsLogger(); - initializeEnvironment(getActionVersion()); - const gitHubVersion = await getGitHubVersion(); - checkActionVersion(getActionVersion(), gitHubVersion); - persistInputs(); - const repositoryNwo = getRepositoryNwo(); - const features = new Features( - gitHubVersion, - repositoryNwo, - getTemporaryDirectory(), - logger - ); - const startingStatusReportBase = await createStatusReportBase( - "upload-sarif" /* UploadSarif */, - "starting", - startedAt, - void 0, - await checkDiskUsage(logger), - logger - ); - if (startingStatusReportBase !== void 0) { - await sendStatusReport(startingStatusReportBase); - } try { + initializeEnvironment(getActionVersion()); + const gitHubVersion = await getGitHubVersion(); + checkActionVersion(getActionVersion(), gitHubVersion); + persistInputs(); + const repositoryNwo = getRepositoryNwo(); + const features = new Features( + gitHubVersion, + repositoryNwo, + getTemporaryDirectory(), + logger + ); + const startingStatusReportBase = await createStatusReportBase( + "upload-sarif" /* UploadSarif */, + "starting", + startedAt, + void 0, + await checkDiskUsage(logger), + logger + ); + if (startingStatusReportBase !== void 0) { + await sendStatusReport(startingStatusReportBase); + } const sarifPath = getRequiredInput("sarif_file"); const checkoutPath = getRequiredInput("checkout_path"); const category = getOptionalInput("category"); diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 6f45ee5f17..f39fc36084 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -222,14 +222,15 @@ async function run() { let didUploadTrapCaches = false; let dependencyCacheResults: DependencyCacheUploadStatusReport | undefined; let databaseUploadResults: DatabaseUploadResult[] = []; - util.initializeEnvironment(actionsUtil.getActionVersion()); - - // Make inputs accessible in the `post` step, details at - // https://github.com/github/codeql-action/issues/2553 - actionsUtil.persistInputs(); - const logger = getActionsLogger(); + try { + util.initializeEnvironment(actionsUtil.getActionVersion()); + + // Make inputs accessible in the `post` step, details at + // https://github.com/github/codeql-action/issues/2553 + actionsUtil.persistInputs(); + const statusReportBase = await createStatusReportBase( ActionName.Analyze, "starting", diff --git a/src/init-action.ts b/src/init-action.ts index c363494566..f91e964219 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -16,7 +16,7 @@ import { persistInputs, } from "./actions-util"; import { AnalysisKind, getAnalysisKinds } from "./analyses"; -import { getGitHubVersion } from "./api-client"; +import { getGitHubVersion, GitHubApiCombinedDetails } from "./api-client"; import { getDependencyCachingEnabled, getTotalCacheSize, @@ -194,65 +194,70 @@ async function sendCompletedStatusReport( async function run() { const startedAt = new Date(); const logger = getActionsLogger(); - initializeEnvironment(getActionVersion()); - - // Make inputs accessible in the `post` step. - persistInputs(); + let apiDetails: GitHubApiCombinedDetails; let config: configUtils.Config | undefined; + let configFile: string | undefined; let codeql: CodeQL; + let features: Features; + let sourceRoot: string; let toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined; let toolsFeatureFlagsValid: boolean | undefined; let toolsSource: ToolsSource; let toolsVersion: string; let zstdAvailability: ZstdAvailability | undefined; - const apiDetails = { - auth: getRequiredInput("token"), - externalRepoAuth: getOptionalInput("external-repository-token"), - url: getRequiredEnvParam("GITHUB_SERVER_URL"), - apiURL: getRequiredEnvParam("GITHUB_API_URL"), - }; + try { + initializeEnvironment(getActionVersion()); + + // Make inputs accessible in the `post` step. + persistInputs(); - const gitHubVersion = await getGitHubVersion(); - checkGitHubVersionInRange(gitHubVersion, logger); - checkActionVersion(getActionVersion(), gitHubVersion); + apiDetails = { + auth: getRequiredInput("token"), + externalRepoAuth: getOptionalInput("external-repository-token"), + url: getRequiredEnvParam("GITHUB_SERVER_URL"), + apiURL: getRequiredEnvParam("GITHUB_API_URL"), + }; - const repositoryNwo = getRepositoryNwo(); + const gitHubVersion = await getGitHubVersion(); + checkGitHubVersionInRange(gitHubVersion, logger); + checkActionVersion(getActionVersion(), gitHubVersion); - const features = new Features( - gitHubVersion, - repositoryNwo, - getTemporaryDirectory(), - logger, - ); + const repositoryNwo = getRepositoryNwo(); - // Fetch the values of known repository properties that affect us. - const enableRepoProps = await features.getValue( - Feature.UseRepositoryProperties, - ); - const repositoryProperties = enableRepoProps - ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) - : {}; + features = new Features( + gitHubVersion, + repositoryNwo, + getTemporaryDirectory(), + logger, + ); + + // Fetch the values of known repository properties that affect us. + const enableRepoProps = await features.getValue( + Feature.UseRepositoryProperties, + ); + const repositoryProperties = enableRepoProps + ? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) + : {}; - // Create a unique identifier for this run. - const jobRunUuid = uuidV4(); - logger.info(`Job run UUID is ${jobRunUuid}.`); - core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid); + // Create a unique identifier for this run. + const jobRunUuid = uuidV4(); + logger.info(`Job run UUID is ${jobRunUuid}.`); + core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid); - core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true"); + core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true"); - const configFile = getOptionalInput("config-file"); + configFile = getOptionalInput("config-file"); - // path.resolve() respects the intended semantics of source-root. If - // source-root is relative, it is relative to the GITHUB_WORKSPACE. If - // source-root is absolute, it is used as given. - const sourceRoot = path.resolve( - getRequiredEnvParam("GITHUB_WORKSPACE"), - getOptionalInput("source-root") || "", - ); + // path.resolve() respects the intended semantics of source-root. If + // source-root is relative, it is relative to the GITHUB_WORKSPACE. If + // source-root is absolute, it is used as given. + sourceRoot = path.resolve( + getRequiredEnvParam("GITHUB_WORKSPACE"), + getOptionalInput("source-root") || "", + ); - try { // Parsing the `analysis-kinds` input may throw a `ConfigurationError`, which we don't want before // we have called `sendStartingStatusReport` below. However, we want the analysis kinds for that status // report. To work around this, we ignore exceptions that are thrown here and then call `getAnalysisKinds` diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index af817b76a4..664bf69e89 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -88,7 +88,6 @@ async function sendCompletedStatusReport( async function run(): Promise { const startedAt = new Date(); const logger = getActionsLogger(); - initializeEnvironment(getActionVersion()); let codeql: CodeQL; let toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined; @@ -96,31 +95,33 @@ async function run(): Promise { let toolsSource: ToolsSource; let toolsVersion: string; - const apiDetails = { - auth: getRequiredInput("token"), - externalRepoAuth: getOptionalInput("external-repository-token"), - url: getRequiredEnvParam("GITHUB_SERVER_URL"), - apiURL: getRequiredEnvParam("GITHUB_API_URL"), - }; + try { + initializeEnvironment(getActionVersion()); - const gitHubVersion = await getGitHubVersion(); - checkGitHubVersionInRange(gitHubVersion, logger); - checkActionVersion(getActionVersion(), gitHubVersion); + const apiDetails = { + auth: getRequiredInput("token"), + externalRepoAuth: getOptionalInput("external-repository-token"), + url: getRequiredEnvParam("GITHUB_SERVER_URL"), + apiURL: getRequiredEnvParam("GITHUB_API_URL"), + }; - const repositoryNwo = getRepositoryNwo(); + const gitHubVersion = await getGitHubVersion(); + checkGitHubVersionInRange(gitHubVersion, logger); + checkActionVersion(getActionVersion(), gitHubVersion); - const features = new Features( - gitHubVersion, - repositoryNwo, - getTemporaryDirectory(), - logger, - ); + const repositoryNwo = getRepositoryNwo(); - const jobRunUuid = uuidV4(); - logger.info(`Job run UUID is ${jobRunUuid}.`); - core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid); + const features = new Features( + gitHubVersion, + repositoryNwo, + getTemporaryDirectory(), + logger, + ); + + const jobRunUuid = uuidV4(); + logger.info(`Job run UUID is ${jobRunUuid}.`); + core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid); - try { const statusReportBase = await createStatusReportBase( ActionName.SetupCodeQL, "starting", diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 013382716b..094ecc3523 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -125,13 +125,13 @@ async function sendSuccessStatusReport( async function runWrapper() { const startedAt = new Date(); - // Make inputs accessible in the `post` step. - actionsUtil.persistInputs(); - const logger = getActionsLogger(); let language: KnownLanguage | undefined; try { + // Make inputs accessible in the `post` step. + actionsUtil.persistInputs(); + // Setup logging for the proxy const tempDir = actionsUtil.getTemporaryDirectory(); const proxyLogFilePath = path.resolve(tempDir, "proxy.log"); diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index 338c9b6dc3..c676d43dab 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -56,35 +56,36 @@ async function sendSuccessStatusReport( async function run() { const startedAt = new Date(); const logger = getActionsLogger(); - initializeEnvironment(getActionVersion()); - const gitHubVersion = await getGitHubVersion(); - checkActionVersion(getActionVersion(), gitHubVersion); + try { + initializeEnvironment(getActionVersion()); - // Make inputs accessible in the `post` step. - actionsUtil.persistInputs(); + const gitHubVersion = await getGitHubVersion(); + checkActionVersion(getActionVersion(), gitHubVersion); - const repositoryNwo = getRepositoryNwo(); - const features = new Features( - gitHubVersion, - repositoryNwo, - getTemporaryDirectory(), - logger, - ); + // Make inputs accessible in the `post` step. + actionsUtil.persistInputs(); - const startingStatusReportBase = await createStatusReportBase( - ActionName.UploadSarif, - "starting", - startedAt, - undefined, - await checkDiskUsage(logger), - logger, - ); - if (startingStatusReportBase !== undefined) { - await sendStatusReport(startingStatusReportBase); - } + const repositoryNwo = getRepositoryNwo(); + const features = new Features( + gitHubVersion, + repositoryNwo, + getTemporaryDirectory(), + logger, + ); + + const startingStatusReportBase = await createStatusReportBase( + ActionName.UploadSarif, + "starting", + startedAt, + undefined, + await checkDiskUsage(logger), + logger, + ); + if (startingStatusReportBase !== undefined) { + await sendStatusReport(startingStatusReportBase); + } - try { // `sarifPath` can either be a path to a single file, or a path to a directory. const sarifPath = actionsUtil.getRequiredInput("sarif_file"); const checkoutPath = actionsUtil.getRequiredInput("checkout_path"); From b715292b74971afcf67e1c903251b820ce5473b3 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 22 Jan 2026 11:27:46 +0000 Subject: [PATCH 02/10] Move config saving within try-catch --- lib/init-action.js | 2 +- src/init-action.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index ae69001c19..7d9a71498b 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92878,6 +92878,7 @@ exec ${goBinaryPath} "$@"` } } flushDiagnostics(config); + await saveConfig(config, logger); core13.setOutput("codeql-path", config.codeQLCmd); core13.setOutput("codeql-version", (await codeql.getVersion()).version); } catch (unwrappedError) { @@ -92901,7 +92902,6 @@ exec ${goBinaryPath} "$@"` } finally { logUnwrittenDiagnostics(); } - await saveConfig(config, logger); await sendCompletedStatusReport( startedAt, config, diff --git a/src/init-action.ts b/src/init-action.ts index f91e964219..19eecbde1e 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -730,6 +730,12 @@ async function run() { // did not exist until now. flushDiagnostics(config); + // We save the config here instead of at the end of `initConfig` because we + // may have updated the config returned from `initConfig`, e.g. to revert to + // `OverlayDatabaseMode.None` if we failed to download an overlay-base + // database. + await configUtils.saveConfig(config, logger); + core.setOutput("codeql-path", config.codeQLCmd); core.setOutput("codeql-version", (await codeql.getVersion()).version); } catch (unwrappedError) { @@ -752,12 +758,6 @@ async function run() { } finally { logUnwrittenDiagnostics(); } - - // We save the config here instead of at the end of `initConfig` because we - // may have updated the config returned from `initConfig`, e.g. to revert to - // `OverlayDatabaseMode.None` if we failed to download an overlay-base - // database. - await configUtils.saveConfig(config, logger); await sendCompletedStatusReport( startedAt, config, From 14bd76753f44c321e098d5a23bdc887ab0e9ea2c Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 22 Jan 2026 11:31:17 +0000 Subject: [PATCH 03/10] Add reminder to minimise code outside try/catch --- src/analyze-action-post.ts | 3 +++ src/analyze-action.ts | 3 +++ src/autobuild-action.ts | 3 +++ src/init-action-post.ts | 3 +++ src/init-action.ts | 3 +++ src/resolve-environment-action.ts | 3 +++ src/setup-codeql-action.ts | 3 +++ src/start-proxy-action-post.ts | 3 +++ src/start-proxy-action.ts | 3 +++ src/upload-sarif-action-post.ts | 3 +++ src/upload-sarif-action.ts | 3 +++ 11 files changed, 33 insertions(+) diff --git a/src/analyze-action-post.ts b/src/analyze-action-post.ts index ce8ddd31bb..c83c102826 100644 --- a/src/analyze-action-post.ts +++ b/src/analyze-action-post.ts @@ -21,6 +21,9 @@ import { getActionsLogger } from "./logging"; import { checkGitHubVersionInRange, getErrorMessage } from "./util"; async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + try { actionsUtil.restoreInputs(); const logger = getActionsLogger(); diff --git a/src/analyze-action.ts b/src/analyze-action.ts index f39fc36084..460e6d55a7 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -209,6 +209,9 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) { } async function run() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); let uploadResults: | Partial> diff --git a/src/autobuild-action.ts b/src/autobuild-action.ts index 0cdf198a4d..b09bff69bc 100644 --- a/src/autobuild-action.ts +++ b/src/autobuild-action.ts @@ -69,6 +69,9 @@ async function sendCompletedStatusReport( } async function run() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); const logger = getActionsLogger(); let config: Config | undefined; diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 9a93f38bc7..59979dca8c 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -42,6 +42,9 @@ interface InitPostStatusReport initActionPostHelper.DependencyCachingUsageReport {} async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const logger = getActionsLogger(); const startedAt = new Date(); let config: Config | undefined; diff --git a/src/init-action.ts b/src/init-action.ts index 19eecbde1e..55ea187a39 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -192,6 +192,9 @@ async function sendCompletedStatusReport( } async function run() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); const logger = getActionsLogger(); diff --git a/src/resolve-environment-action.ts b/src/resolve-environment-action.ts index 459f471ae8..4f68fb8ac7 100644 --- a/src/resolve-environment-action.ts +++ b/src/resolve-environment-action.ts @@ -30,6 +30,9 @@ import { const ENVIRONMENT_OUTPUT_NAME = "environment"; async function run() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); const logger = getActionsLogger(); diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index 664bf69e89..166e3c2dee 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -86,6 +86,9 @@ async function sendCompletedStatusReport( /** The main behaviour of this action. */ async function run(): Promise { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); const logger = getActionsLogger(); diff --git a/src/start-proxy-action-post.ts b/src/start-proxy-action-post.ts index c1e3209d1b..5a1d8d6fcb 100644 --- a/src/start-proxy-action-post.ts +++ b/src/start-proxy-action-post.ts @@ -13,6 +13,9 @@ import { getActionsLogger } from "./logging"; import { checkGitHubVersionInRange, getErrorMessage } from "./util"; async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const logger = getActionsLogger(); try { diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 094ecc3523..98b765291e 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -123,6 +123,9 @@ async function sendSuccessStatusReport( } async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); const logger = getActionsLogger(); diff --git a/src/upload-sarif-action-post.ts b/src/upload-sarif-action-post.ts index 9852b882b9..a184916de4 100644 --- a/src/upload-sarif-action-post.ts +++ b/src/upload-sarif-action-post.ts @@ -13,6 +13,9 @@ import { getActionsLogger, withGroup } from "./logging"; import { checkGitHubVersionInRange, getErrorMessage } from "./util"; async function runWrapper() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + try { // Restore inputs from `upload-sarif` Action. actionsUtil.restoreInputs(); diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index c676d43dab..e37a7c5246 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -54,6 +54,9 @@ async function sendSuccessStatusReport( } async function run() { + // To capture errors appropriately, keep as much code within the try-catch as + // possible, and only use safe functions outside. + const startedAt = new Date(); const logger = getActionsLogger(); From 229e0cd749ce78f208cfaa2ce84d68ada1fd01ff Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 22 Jan 2026 13:14:53 +0000 Subject: [PATCH 04/10] Add catch-all error reporting for errors that slip through `run` --- lib/analyze-action.js | 48 +++++++++--- lib/autobuild-action.js | 34 ++++++++- lib/init-action-post.js | 117 +++++++++++++++++++----------- lib/init-action.js | 34 ++++++++- lib/resolve-environment-action.js | 34 ++++++++- lib/setup-codeql-action.js | 34 ++++++++- lib/start-proxy-action.js | 59 ++++++++++++--- lib/upload-sarif-action.js | 34 ++++++++- src/analyze-action.ts | 15 +++- src/autobuild-action.ts | 14 +++- src/init-action-post.ts | 20 ++++- src/init-action.ts | 14 +++- src/resolve-environment-action.ts | 14 +++- src/setup-codeql-action.ts | 14 +++- src/start-proxy-action.ts | 22 +++++- src/status-report.ts | 27 +++++++ src/upload-sarif-action.ts | 14 +++- 17 files changed, 447 insertions(+), 101 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 8a00e01cce..6c4bd46e70 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -94410,6 +94410,27 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/upload-lib.ts var fs15 = __toESM(require("fs")); @@ -96241,12 +96262,12 @@ async function postProcessAndUploadSarif(logger, features, uploadKind, checkoutP } // src/analyze-action.ts -async function sendStatusReport2(startedAt, config, stats, error3, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, databaseUploadResults, logger) { +async function sendStatusReport2(startedAt2, config, stats, error3, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, databaseUploadResults, logger) { const status = getActionsStatus(error3, stats?.analyze_failure_language); const statusReportBase = await createStatusReportBase( "finish" /* Analyze */, status, - startedAt, + startedAt2, config, await checkDiskUsage(logger), logger, @@ -96332,8 +96353,7 @@ async function runAutobuildIfLegacyGoWorkflow(config, logger) { ); await runAutobuild(config, "go" /* go */, logger); } -async function run() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt2) { let uploadResults = void 0; let runStats = void 0; let config = void 0; @@ -96350,7 +96370,7 @@ async function run() { const statusReportBase = await createStatusReportBase( "finish" /* Analyze */, "starting", - startedAt, + startedAt2, config, await checkDiskUsage(logger), logger @@ -96517,7 +96537,7 @@ async function run() { core14.setFailed(error3.message); } await sendStatusReport2( - startedAt, + startedAt2, config, error3 instanceof CodeQLAnalysisError ? error3.queriesStatusReport : void 0, error3 instanceof CodeQLAnalysisError ? error3.error : error3, @@ -96533,7 +96553,7 @@ async function run() { } if (runStats !== void 0 && uploadResults?.["code-scanning" /* CodeScanning */] !== void 0) { await sendStatusReport2( - startedAt, + startedAt2, config, { ...runStats, @@ -96550,7 +96570,7 @@ async function run() { ); } else if (runStats !== void 0) { await sendStatusReport2( - startedAt, + startedAt2, config, { ...runStats }, void 0, @@ -96564,7 +96584,7 @@ async function run() { ); } else { await sendStatusReport2( - startedAt, + startedAt2, config, void 0, void 0, @@ -96578,12 +96598,20 @@ async function run() { ); } } -var runPromise = run(); +var startedAt = /* @__PURE__ */ new Date(); +var runPromise = run(startedAt); async function runWrapper() { + const logger = getActionsLogger(); try { await runPromise; } catch (error3) { core14.setFailed(`analyze action failed: ${getErrorMessage(error3)}`); + await sendUnexpectedErrorStatusReport( + "finish" /* Analyze */, + startedAt, + error3, + logger + ); } await checkForTimeout(); } diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 5445cc0f96..2fb42470df 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -88882,6 +88882,27 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/autobuild-action.ts async function sendCompletedStatusReport(config, logger, startedAt, allLanguages, failingLanguage, cause) { @@ -88906,8 +88927,7 @@ async function sendCompletedStatusReport(config, logger, startedAt, allLanguages await sendStatusReport(statusReport); } } -async function run() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt) { const logger = getActionsLogger(); let config; let currentLanguage; @@ -88968,10 +88988,18 @@ async function run() { await sendCompletedStatusReport(config, logger, startedAt, languages ?? []); } async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error3) { core13.setFailed(`autobuild action failed. ${getErrorMessage(error3)}`); + await sendUnexpectedErrorStatusReport( + "autobuild" /* Autobuild */, + startedAt, + error3, + logger + ); } } void runWrapper(); diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 4b0e498104..8b1d142be4 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -27121,7 +27121,7 @@ var require_light = __commonJS({ } return this.Events.trigger("scheduled", { args: this.args, options: this.options }); } - async doExecute(chained, clearGlobalState, run2, free) { + async doExecute(chained, clearGlobalState, run3, free) { var error3, eventInfo, passed; if (this.retryCount === 0) { this._assertStatus("RUNNING"); @@ -27141,10 +27141,10 @@ var require_light = __commonJS({ } } catch (error1) { error3 = error1; - return this._onFailure(error3, eventInfo, clearGlobalState, run2, free); + return this._onFailure(error3, eventInfo, clearGlobalState, run3, free); } } - doExpire(clearGlobalState, run2, free) { + doExpire(clearGlobalState, run3, free) { var error3, eventInfo; if (this._states.jobStatus(this.options.id === "RUNNING")) { this._states.next(this.options.id); @@ -27152,9 +27152,9 @@ var require_light = __commonJS({ this._assertStatus("EXECUTING"); eventInfo = { args: this.args, options: this.options, retryCount: this.retryCount }; error3 = new BottleneckError$1(`This job timed out after ${this.options.expiration} ms.`); - return this._onFailure(error3, eventInfo, clearGlobalState, run2, free); + return this._onFailure(error3, eventInfo, clearGlobalState, run3, free); } - async _onFailure(error3, eventInfo, clearGlobalState, run2, free) { + async _onFailure(error3, eventInfo, clearGlobalState, run3, free) { var retry3, retryAfter; if (clearGlobalState()) { retry3 = await this.Events.trigger("failed", error3, eventInfo); @@ -27162,7 +27162,7 @@ var require_light = __commonJS({ retryAfter = ~~retry3; this.Events.trigger("retry", `Retrying ${this.options.id} after ${retryAfter} ms`, eventInfo); this.retryCount++; - return run2(retryAfter); + return run3(retryAfter); } else { this.doDone(eventInfo); await free(this.options, eventInfo); @@ -27800,17 +27800,17 @@ var require_light = __commonJS({ } } _run(index, job, wait) { - var clearGlobalState, free, run2; + var clearGlobalState, free, run3; job.doRun(); clearGlobalState = this._clearGlobalState.bind(this, index); - run2 = this._run.bind(this, index, job); + run3 = this._run.bind(this, index, job); free = this._free.bind(this, index, job); return this._scheduled[index] = { timeout: setTimeout(() => { - return job.doExecute(this._limiter, clearGlobalState, run2, free); + return job.doExecute(this._limiter, clearGlobalState, run3, free); }, wait), expiration: job.options.expiration != null ? setTimeout(function() { - return job.doExpire(clearGlobalState, run2, free); + return job.doExpire(clearGlobalState, run3, free); }, wait + job.options.expiration) : void 0, job }; @@ -88091,8 +88091,8 @@ var require_async = __commonJS({ return callback(null, results); } while (readyTasks.length && runningTasks < concurrency) { - var run2 = readyTasks.shift(); - run2(); + var run3 = readyTasks.shift(); + run3(); } } function addListener(taskName, fn) { @@ -126644,8 +126644,8 @@ function getExtraOptionsEnvParam() { } function getToolNames(sarif) { const toolNames = {}; - for (const run2 of sarif.runs || []) { - const tool = run2.tool || {}; + for (const run3 of sarif.runs || []) { + const tool = run3.tool || {}; const driver = tool.driver || {}; if (typeof driver.name === "string" && driver.name.length > 0) { toolNames[driver.name] = true; @@ -130773,6 +130773,27 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/upload-lib.ts var fs15 = __toESM(require("fs")); @@ -131861,9 +131882,9 @@ async function addFingerprints(sarif, sourceRoot, logger) { `Adding fingerprints to SARIF file. See ${"https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#providing-data-to-track-code-scanning-alerts-across-runs" /* TRACK_CODE_SCANNING_ALERTS_ACROSS_RUNS */} for more information.` ); const callbacksByFile = {}; - for (const run2 of sarif.runs || []) { - const artifacts = run2.artifacts || []; - for (const result of run2.results || []) { + for (const run3 of sarif.runs || []) { + const artifacts = run3.artifacts || []; + for (const result of run3.results || []) { const primaryLocation = (result.locations || [])[0]; if (!primaryLocation?.physicalLocation?.artifactLocation) { logger.debug( @@ -131964,25 +131985,25 @@ function combineSarifFiles(sarifFiles, logger) { function areAllRunsProducedByCodeQL(sarifObjects) { return sarifObjects.every((sarifObject) => { return sarifObject.runs?.every( - (run2) => run2.tool?.driver?.name === "CodeQL" + (run3) => run3.tool?.driver?.name === "CodeQL" ); }); } -function createRunKey(run2) { +function createRunKey(run3) { return { - name: run2.tool?.driver?.name, - fullName: run2.tool?.driver?.fullName, - version: run2.tool?.driver?.version, - semanticVersion: run2.tool?.driver?.semanticVersion, - guid: run2.tool?.driver?.guid, - automationId: run2.automationDetails?.id + name: run3.tool?.driver?.name, + fullName: run3.tool?.driver?.fullName, + version: run3.tool?.driver?.version, + semanticVersion: run3.tool?.driver?.semanticVersion, + guid: run3.tool?.driver?.guid, + automationId: run3.automationDetails?.id }; } function areAllRunsUnique(sarifObjects) { const keys = /* @__PURE__ */ new Set(); for (const sarifObject of sarifObjects) { - for (const run2 of sarifObject.runs) { - const key = JSON.stringify(createRunKey(run2)); + for (const run3 of sarifObject.runs) { + const key = JSON.stringify(createRunKey(run3)); if (keys.has(key)) { return false; } @@ -132085,9 +132106,9 @@ async function combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, lo function populateRunAutomationDetails(sarif, category, analysis_key, environment) { const automationID = getAutomationID2(category, analysis_key, environment); if (automationID !== void 0) { - for (const run2 of sarif.runs || []) { - if (run2.automationDetails === void 0) { - run2.automationDetails = { + for (const run3 of sarif.runs || []) { + if (run3.automationDetails === void 0) { + run3.automationDetails = { id: automationID }; } @@ -132186,13 +132207,13 @@ function countResultsInSarif(sarif) { if (!Array.isArray(parsedSarif.runs)) { throw new InvalidSarifUploadError("Invalid SARIF. Missing 'runs' array."); } - for (const run2 of parsedSarif.runs) { - if (!Array.isArray(run2.results)) { + for (const run3 of parsedSarif.runs) { + if (!Array.isArray(run3.results)) { throw new InvalidSarifUploadError( "Invalid SARIF. Missing 'results' array in run." ); } - numResults += run2.results.length; + numResults += run3.results.length; } return numResults; } @@ -132483,9 +132504,9 @@ function handleProcessingResultForUnsuccessfulExecution(response, status, logger } function validateUniqueCategory(sarif, sentinelPrefix) { const categories = {}; - for (const run2 of sarif.runs) { - const id = run2?.automationDetails?.id; - const tool = run2.tool?.driver?.name; + for (const run3 of sarif.runs) { + const id = run3?.automationDetails?.id; + const tool = run3.tool?.driver?.name; const category = `${sanitize(id)}_${sanitize(tool)}`; categories[category] = { id, tool }; } @@ -132513,9 +132534,9 @@ function filterAlertsByDiffRange(logger, sarif) { return sarif; } const checkoutPath = getRequiredInput("checkout_path"); - for (const run2 of sarif.runs) { - if (run2.results) { - run2.results = run2.results.filter((result) => { + for (const run3 of sarif.runs) { + if (run3.results) { + run3.results = run3.results.filter((result) => { const locations = [ ...(result.locations || []).map((loc) => loc.physicalLocation), ...(result.relatedLocations || []).map((loc) => loc.physicalLocation) @@ -132881,9 +132902,8 @@ function getFinalJobStatus() { } // src/init-action-post.ts -async function runWrapper() { +async function run2(startedAt) { const logger = getActionsLogger(); - const startedAt = /* @__PURE__ */ new Date(); let config; let uploadFailedSarifResult; let dependencyCachingUsage; @@ -132958,6 +132978,21 @@ async function runWrapper() { logger.info("Status report sent for init-post step."); } } +async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); + try { + await run2(startedAt); + } catch (error3) { + core17.setFailed(`init post action failed: ${wrapError(error3).message}`); + await sendUnexpectedErrorStatusReport( + "init-post" /* InitPost */, + startedAt, + error3, + logger + ); + } +} void runWrapper(); /*! Bundled license information: diff --git a/lib/init-action.js b/lib/init-action.js index 7d9a71498b..07d248a7a3 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92247,6 +92247,27 @@ async function createInitWithConfigStatusReport(config, initStatusReport, config ) }; } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/workflow.ts var fs13 = __toESM(require("fs")); @@ -92503,8 +92524,7 @@ async function sendCompletedStatusReport(startedAt, config, configFile, toolsDow await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields }); } } -async function run() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt) { const logger = getActionsLogger(); let apiDetails; let config; @@ -92935,10 +92955,18 @@ async function recordZstdAvailability(config, zstdAvailability) { ); } async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error3) { core13.setFailed(`init action failed: ${getErrorMessage(error3)}`); + await sendUnexpectedErrorStatusReport( + "init" /* Init */, + startedAt, + error3, + logger + ); } await checkForTimeout(); } diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 0a1774f2aa..eb2a509adf 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -88502,11 +88502,31 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/resolve-environment-action.ts var ENVIRONMENT_OUTPUT_NAME = "environment"; -async function run() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt) { const logger = getActionsLogger(); let config; try { @@ -88578,14 +88598,22 @@ async function run() { } } async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error3) { core12.setFailed( `${"resolve-environment" /* ResolveEnvironment */} action failed: ${getErrorMessage( error3 )}` ); + await sendUnexpectedErrorStatusReport( + "resolve-environment" /* ResolveEnvironment */, + startedAt, + error3, + logger + ); } await checkForTimeout(); } diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 0f57e54614..191a5b427f 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89829,6 +89829,27 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/setup-codeql-action.ts async function sendCompletedStatusReport(startedAt, toolsDownloadStatusReport, toolsFeatureFlagsValid, toolsSource, toolsVersion, logger, error3) { @@ -89861,8 +89882,7 @@ async function sendCompletedStatusReport(startedAt, toolsDownloadStatusReport, t } await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields }); } -async function run() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt) { const logger = getActionsLogger(); let codeql; let toolsDownloadStatusReport; @@ -89949,10 +89969,18 @@ async function run() { ); } async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error3) { core12.setFailed(`setup-codeql action failed: ${getErrorMessage(error3)}`); + await sendUnexpectedErrorStatusReport( + "setup-codeql" /* SetupCodeQL */, + startedAt, + error3, + logger + ); } await checkForTimeout(); } diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 4b7f556ec0..a262056057 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -45727,7 +45727,7 @@ var require_light = __commonJS({ } return this.Events.trigger("scheduled", { args: this.args, options: this.options }); } - async doExecute(chained, clearGlobalState, run, free) { + async doExecute(chained, clearGlobalState, run2, free) { var error3, eventInfo, passed; if (this.retryCount === 0) { this._assertStatus("RUNNING"); @@ -45747,10 +45747,10 @@ var require_light = __commonJS({ } } catch (error1) { error3 = error1; - return this._onFailure(error3, eventInfo, clearGlobalState, run, free); + return this._onFailure(error3, eventInfo, clearGlobalState, run2, free); } } - doExpire(clearGlobalState, run, free) { + doExpire(clearGlobalState, run2, free) { var error3, eventInfo; if (this._states.jobStatus(this.options.id === "RUNNING")) { this._states.next(this.options.id); @@ -45758,9 +45758,9 @@ var require_light = __commonJS({ this._assertStatus("EXECUTING"); eventInfo = { args: this.args, options: this.options, retryCount: this.retryCount }; error3 = new BottleneckError$1(`This job timed out after ${this.options.expiration} ms.`); - return this._onFailure(error3, eventInfo, clearGlobalState, run, free); + return this._onFailure(error3, eventInfo, clearGlobalState, run2, free); } - async _onFailure(error3, eventInfo, clearGlobalState, run, free) { + async _onFailure(error3, eventInfo, clearGlobalState, run2, free) { var retry3, retryAfter; if (clearGlobalState()) { retry3 = await this.Events.trigger("failed", error3, eventInfo); @@ -45768,7 +45768,7 @@ var require_light = __commonJS({ retryAfter = ~~retry3; this.Events.trigger("retry", `Retrying ${this.options.id} after ${retryAfter} ms`, eventInfo); this.retryCount++; - return run(retryAfter); + return run2(retryAfter); } else { this.doDone(eventInfo); await free(this.options, eventInfo); @@ -46406,17 +46406,17 @@ var require_light = __commonJS({ } } _run(index, job, wait) { - var clearGlobalState, free, run; + var clearGlobalState, free, run2; job.doRun(); clearGlobalState = this._clearGlobalState.bind(this, index); - run = this._run.bind(this, index, job); + run2 = this._run.bind(this, index, job); free = this._free.bind(this, index, job); return this._scheduled[index] = { timeout: setTimeout(() => { - return job.doExecute(this._limiter, clearGlobalState, run, free); + return job.doExecute(this._limiter, clearGlobalState, run2, free); }, wait), expiration: job.options.expiration != null ? setTimeout(function() { - return job.doExpire(clearGlobalState, run, free); + return job.doExpire(clearGlobalState, run2, free); }, wait + job.options.expiration) : void 0, job }; @@ -104666,6 +104666,27 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/start-proxy-action.ts var KEY_SIZE = 2048; @@ -104731,8 +104752,7 @@ async function sendSuccessStatusReport(startedAt, config, registry_types, logger await sendStatusReport(statusReport); } } -async function runWrapper() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt) { const logger = getActionsLogger(); let language; try { @@ -104789,6 +104809,21 @@ async function runWrapper() { } } } +async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); + try { + await run(startedAt); + } catch (error3) { + core11.setFailed(`start-proxy action failed: ${getErrorMessage(error3)}`); + await sendUnexpectedErrorStatusReport( + "start-proxy" /* StartProxy */, + startedAt, + error3, + logger + ); + } +} async function startProxy(binPath, config, logFilePath, logger) { const host = "127.0.0.1"; let port = 49152; diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index df3c634613..262abd9122 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -91059,6 +91059,27 @@ async function sendStatusReport(statusReport) { ); } } +async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + void 0, + void 0, + logger, + void 0, + getErrorMessage(error3) + ); + if (statusReport !== void 0) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.` + ); + } +} // src/upload-lib.ts var fs12 = __toESM(require("fs")); @@ -94702,8 +94723,7 @@ async function sendSuccessStatusReport(startedAt, uploadStats, logger) { await sendStatusReport(statusReport); } } -async function run() { - const startedAt = /* @__PURE__ */ new Date(); +async function run(startedAt) { const logger = getActionsLogger(); try { initializeEnvironment(getActionVersion()); @@ -94788,12 +94808,20 @@ async function run() { } } async function runWrapper() { + const startedAt = /* @__PURE__ */ new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error3) { core13.setFailed( `codeql/upload-sarif action failed: ${getErrorMessage(error3)}` ); + await sendUnexpectedErrorStatusReport( + "upload-sarif" /* UploadSarif */, + startedAt, + error3, + logger + ); } } void runWrapper(); diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 460e6d55a7..157e3d1d1e 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -41,6 +41,7 @@ import { createStatusReportBase, DatabaseCreationTimings, getActionsStatus, + sendUnexpectedErrorStatusReport, StatusReportBase, } from "./status-report"; import { @@ -208,11 +209,10 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) { await runAutobuild(config, KnownLanguage.go, logger); } -async function run() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); let uploadResults: | Partial> | undefined = undefined; @@ -526,13 +526,22 @@ async function run() { } } -export const runPromise = run(); +// Module-level startedAt so it can be accessed by runWrapper for error reporting +const startedAt = new Date(); +export const runPromise = run(startedAt); async function runWrapper() { + const logger = getActionsLogger(); try { await runPromise; } catch (error) { core.setFailed(`analyze action failed: ${util.getErrorMessage(error)}`); + await sendUnexpectedErrorStatusReport( + ActionName.Analyze, + startedAt, + error, + logger, + ); } await util.checkForTimeout(); } diff --git a/src/autobuild-action.ts b/src/autobuild-action.ts index b09bff69bc..ebcacbc97a 100644 --- a/src/autobuild-action.ts +++ b/src/autobuild-action.ts @@ -17,6 +17,7 @@ import { getActionsStatus, createStatusReportBase, sendStatusReport, + sendUnexpectedErrorStatusReport, ActionName, } from "./status-report"; import { endTracingForCluster } from "./tracer-config"; @@ -68,11 +69,10 @@ async function sendCompletedStatusReport( } } -async function run() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); const logger = getActionsLogger(); let config: Config | undefined; let currentLanguage: Language | undefined; @@ -143,10 +143,18 @@ async function run() { } async function runWrapper() { + const startedAt = new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error) { core.setFailed(`autobuild action failed. ${getErrorMessage(error)}`); + await sendUnexpectedErrorStatusReport( + ActionName.Autobuild, + startedAt, + error, + logger, + ); } } diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 59979dca8c..14fc34408d 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -28,6 +28,7 @@ import { getRepositoryNwo } from "./repository"; import { StatusReportBase, sendStatusReport, + sendUnexpectedErrorStatusReport, createStatusReportBase, getActionsStatus, ActionName, @@ -41,12 +42,11 @@ interface InitPostStatusReport initActionPostHelper.JobStatusReport, initActionPostHelper.DependencyCachingUsageReport {} -async function runWrapper() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. const logger = getActionsLogger(); - const startedAt = new Date(); let config: Config | undefined; let uploadFailedSarifResult: | initActionPostHelper.UploadFailedSarifResult @@ -139,4 +139,20 @@ async function runWrapper() { } } +async function runWrapper() { + const startedAt = new Date(); + const logger = getActionsLogger(); + try { + await run(startedAt); + } catch (error) { + core.setFailed(`init post action failed: ${wrapError(error).message}`); + await sendUnexpectedErrorStatusReport( + ActionName.InitPost, + startedAt, + error, + logger, + ); + } +} + void runWrapper(); diff --git a/src/init-action.ts b/src/init-action.ts index 55ea187a39..e498e296e9 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -64,6 +64,7 @@ import { createStatusReportBase, getActionsStatus, sendStatusReport, + sendUnexpectedErrorStatusReport, } from "./status-report"; import { ZstdAvailability } from "./tar"; import { ToolsDownloadStatusReport } from "./tools-download"; @@ -191,11 +192,10 @@ async function sendCompletedStatusReport( } } -async function run() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); const logger = getActionsLogger(); let apiDetails: GitHubApiCombinedDetails; @@ -805,10 +805,18 @@ async function recordZstdAvailability( } async function runWrapper() { + const startedAt = new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error) { core.setFailed(`init action failed: ${getErrorMessage(error)}`); + await sendUnexpectedErrorStatusReport( + ActionName.Init, + startedAt, + error, + logger, + ); } await checkForTimeout(); } diff --git a/src/resolve-environment-action.ts b/src/resolve-environment-action.ts index 4f68fb8ac7..fc96ec9adf 100644 --- a/src/resolve-environment-action.ts +++ b/src/resolve-environment-action.ts @@ -13,6 +13,7 @@ import { getActionsLogger } from "./logging"; import { runResolveBuildEnvironment } from "./resolve-environment"; import { sendStatusReport, + sendUnexpectedErrorStatusReport, createStatusReportBase, getActionsStatus, ActionName, @@ -29,11 +30,10 @@ import { const ENVIRONMENT_OUTPUT_NAME = "environment"; -async function run() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); const logger = getActionsLogger(); let config: Config | undefined; @@ -118,14 +118,22 @@ async function run() { } async function runWrapper() { + const startedAt = new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error) { core.setFailed( `${ActionName.ResolveEnvironment} action failed: ${getErrorMessage( error, )}`, ); + await sendUnexpectedErrorStatusReport( + ActionName.ResolveEnvironment, + startedAt, + error, + logger, + ); } await checkForTimeout(); } diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index 166e3c2dee..55bcaa7e0b 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -22,6 +22,7 @@ import { createStatusReportBase, getActionsStatus, sendStatusReport, + sendUnexpectedErrorStatusReport, } from "./status-report"; import { ToolsDownloadStatusReport } from "./tools-download"; import { @@ -85,11 +86,10 @@ async function sendCompletedStatusReport( } /** The main behaviour of this action. */ -async function run(): Promise { +async function run(startedAt: Date): Promise { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); const logger = getActionsLogger(); let codeql: CodeQL; @@ -189,10 +189,18 @@ async function run(): Promise { /** Run the action and catch any unhandled errors. */ async function runWrapper(): Promise { + const startedAt = new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error) { core.setFailed(`setup-codeql action failed: ${getErrorMessage(error)}`); + await sendUnexpectedErrorStatusReport( + ActionName.SetupCodeQL, + startedAt, + error, + logger, + ); } await checkForTimeout(); } diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 98b765291e..51bdc55998 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -22,6 +22,7 @@ import { createStatusReportBase, getActionsStatus, sendStatusReport, + sendUnexpectedErrorStatusReport, StatusReportBase, } from "./status-report"; import * as util from "./util"; @@ -122,12 +123,10 @@ async function sendSuccessStatusReport( } } -async function runWrapper() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); - const logger = getActionsLogger(); let language: KnownLanguage | undefined; @@ -203,6 +202,23 @@ async function runWrapper() { } } +async function runWrapper() { + const startedAt = new Date(); + const logger = getActionsLogger(); + + try { + await run(startedAt); + } catch (error) { + core.setFailed(`start-proxy action failed: ${util.getErrorMessage(error)}`); + await sendUnexpectedErrorStatusReport( + ActionName.StartProxy, + startedAt, + error, + logger, + ); + } +} + async function startProxy( binPath: string, config: ProxyConfig, diff --git a/src/status-report.ts b/src/status-report.ts index c6e747489e..3c5efa6e6e 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -606,3 +606,30 @@ export async function createInitWithConfigStatusReport( ), }; } + +export async function sendUnexpectedErrorStatusReport( + actionName: ActionName, + actionStartedAt: Date, + error: unknown, + logger: Logger, +): Promise { + try { + const statusReport = await createStatusReportBase( + actionName, + "failure", + actionStartedAt, + undefined, + undefined, + logger, + undefined, + getErrorMessage(error), + ); + if (statusReport !== undefined) { + await sendStatusReport(statusReport); + } + } catch (e) { + logger.warning( + `Caught an exception while sending the error status report: ${e}.`, + ); + } +} diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index e37a7c5246..08d9c0d24e 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -10,6 +10,7 @@ import { getRepositoryNwo } from "./repository"; import { createStatusReportBase, sendStatusReport, + sendUnexpectedErrorStatusReport, StatusReportBase, getActionsStatus, ActionName, @@ -53,11 +54,10 @@ async function sendSuccessStatusReport( } } -async function run() { +async function run(startedAt: Date) { // To capture errors appropriately, keep as much code within the try-catch as // possible, and only use safe functions outside. - const startedAt = new Date(); const logger = getActionsLogger(); try { @@ -165,12 +165,20 @@ async function run() { } async function runWrapper() { + const startedAt = new Date(); + const logger = getActionsLogger(); try { - await run(); + await run(startedAt); } catch (error) { core.setFailed( `codeql/upload-sarif action failed: ${getErrorMessage(error)}`, ); + await sendUnexpectedErrorStatusReport( + ActionName.UploadSarif, + startedAt, + error, + logger, + ); } } From 6bd84b6a824e0bd20428e8d4cba001000a9ed83f Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 23 Jan 2026 10:34:45 +0000 Subject: [PATCH 05/10] Rename to "unhandled" --- lib/analyze-action.js | 4 ++-- lib/autobuild-action.js | 4 ++-- lib/init-action-post.js | 4 ++-- lib/init-action.js | 4 ++-- lib/resolve-environment-action.js | 4 ++-- lib/setup-codeql-action.js | 4 ++-- lib/start-proxy-action.js | 4 ++-- lib/upload-sarif-action.js | 4 ++-- src/analyze-action.ts | 4 ++-- src/autobuild-action.ts | 4 ++-- src/init-action-post.ts | 4 ++-- src/init-action.ts | 4 ++-- src/resolve-environment-action.ts | 4 ++-- src/setup-codeql-action.ts | 4 ++-- src/start-proxy-action.ts | 4 ++-- src/status-report.ts | 2 +- src/upload-sarif-action.ts | 4 ++-- 17 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 6c4bd46e70..c8bd4aed09 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -94410,7 +94410,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -96606,7 +96606,7 @@ async function runWrapper() { await runPromise; } catch (error3) { core14.setFailed(`analyze action failed: ${getErrorMessage(error3)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "finish" /* Analyze */, startedAt, error3, diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 2fb42470df..09722eb202 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -88882,7 +88882,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -88994,7 +88994,7 @@ async function runWrapper() { await run(startedAt); } catch (error3) { core13.setFailed(`autobuild action failed. ${getErrorMessage(error3)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "autobuild" /* Autobuild */, startedAt, error3, diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 8b1d142be4..9bc9c637fb 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -130773,7 +130773,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -132985,7 +132985,7 @@ async function runWrapper() { await run2(startedAt); } catch (error3) { core17.setFailed(`init post action failed: ${wrapError(error3).message}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "init-post" /* InitPost */, startedAt, error3, diff --git a/lib/init-action.js b/lib/init-action.js index 07d248a7a3..382979c844 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92247,7 +92247,7 @@ async function createInitWithConfigStatusReport(config, initStatusReport, config ) }; } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -92961,7 +92961,7 @@ async function runWrapper() { await run(startedAt); } catch (error3) { core13.setFailed(`init action failed: ${getErrorMessage(error3)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "init" /* Init */, startedAt, error3, diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index eb2a509adf..86069a98ac 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -88502,7 +88502,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -88608,7 +88608,7 @@ async function runWrapper() { error3 )}` ); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "resolve-environment" /* ResolveEnvironment */, startedAt, error3, diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 191a5b427f..4385b012c8 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89829,7 +89829,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -89975,7 +89975,7 @@ async function runWrapper() { await run(startedAt); } catch (error3) { core12.setFailed(`setup-codeql action failed: ${getErrorMessage(error3)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "setup-codeql" /* SetupCodeQL */, startedAt, error3, diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index a262056057..21a7e0341b 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104666,7 +104666,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -104816,7 +104816,7 @@ async function runWrapper() { await run(startedAt); } catch (error3) { core11.setFailed(`start-proxy action failed: ${getErrorMessage(error3)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "start-proxy" /* StartProxy */, startedAt, error3, diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 262abd9122..c2d42c4f04 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -91059,7 +91059,7 @@ async function sendStatusReport(statusReport) { ); } } -async function sendUnexpectedErrorStatusReport(actionName, actionStartedAt, error3, logger) { +async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error3, logger) { try { const statusReport = await createStatusReportBase( actionName, @@ -94816,7 +94816,7 @@ async function runWrapper() { core13.setFailed( `codeql/upload-sarif action failed: ${getErrorMessage(error3)}` ); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( "upload-sarif" /* UploadSarif */, startedAt, error3, diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 157e3d1d1e..3cc1ad019a 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -41,7 +41,7 @@ import { createStatusReportBase, DatabaseCreationTimings, getActionsStatus, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, StatusReportBase, } from "./status-report"; import { @@ -536,7 +536,7 @@ async function runWrapper() { await runPromise; } catch (error) { core.setFailed(`analyze action failed: ${util.getErrorMessage(error)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.Analyze, startedAt, error, diff --git a/src/autobuild-action.ts b/src/autobuild-action.ts index ebcacbc97a..a1465f1103 100644 --- a/src/autobuild-action.ts +++ b/src/autobuild-action.ts @@ -17,7 +17,7 @@ import { getActionsStatus, createStatusReportBase, sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, ActionName, } from "./status-report"; import { endTracingForCluster } from "./tracer-config"; @@ -149,7 +149,7 @@ async function runWrapper() { await run(startedAt); } catch (error) { core.setFailed(`autobuild action failed. ${getErrorMessage(error)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.Autobuild, startedAt, error, diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 14fc34408d..02a856862a 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -28,7 +28,7 @@ import { getRepositoryNwo } from "./repository"; import { StatusReportBase, sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, createStatusReportBase, getActionsStatus, ActionName, @@ -146,7 +146,7 @@ async function runWrapper() { await run(startedAt); } catch (error) { core.setFailed(`init post action failed: ${wrapError(error).message}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.InitPost, startedAt, error, diff --git a/src/init-action.ts b/src/init-action.ts index e498e296e9..8b6c200a05 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -64,7 +64,7 @@ import { createStatusReportBase, getActionsStatus, sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, } from "./status-report"; import { ZstdAvailability } from "./tar"; import { ToolsDownloadStatusReport } from "./tools-download"; @@ -811,7 +811,7 @@ async function runWrapper() { await run(startedAt); } catch (error) { core.setFailed(`init action failed: ${getErrorMessage(error)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.Init, startedAt, error, diff --git a/src/resolve-environment-action.ts b/src/resolve-environment-action.ts index fc96ec9adf..253a342d7f 100644 --- a/src/resolve-environment-action.ts +++ b/src/resolve-environment-action.ts @@ -13,7 +13,7 @@ import { getActionsLogger } from "./logging"; import { runResolveBuildEnvironment } from "./resolve-environment"; import { sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, createStatusReportBase, getActionsStatus, ActionName, @@ -128,7 +128,7 @@ async function runWrapper() { error, )}`, ); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.ResolveEnvironment, startedAt, error, diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index 55bcaa7e0b..31c8986679 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -22,7 +22,7 @@ import { createStatusReportBase, getActionsStatus, sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, } from "./status-report"; import { ToolsDownloadStatusReport } from "./tools-download"; import { @@ -195,7 +195,7 @@ async function runWrapper(): Promise { await run(startedAt); } catch (error) { core.setFailed(`setup-codeql action failed: ${getErrorMessage(error)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.SetupCodeQL, startedAt, error, diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 51bdc55998..e95643bb07 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -22,7 +22,7 @@ import { createStatusReportBase, getActionsStatus, sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, StatusReportBase, } from "./status-report"; import * as util from "./util"; @@ -210,7 +210,7 @@ async function runWrapper() { await run(startedAt); } catch (error) { core.setFailed(`start-proxy action failed: ${util.getErrorMessage(error)}`); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.StartProxy, startedAt, error, diff --git a/src/status-report.ts b/src/status-report.ts index 3c5efa6e6e..513cdb43ef 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -607,7 +607,7 @@ export async function createInitWithConfigStatusReport( }; } -export async function sendUnexpectedErrorStatusReport( +export async function sendUnhandledErrorStatusReport( actionName: ActionName, actionStartedAt: Date, error: unknown, diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index 08d9c0d24e..5273909bad 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -10,7 +10,7 @@ import { getRepositoryNwo } from "./repository"; import { createStatusReportBase, sendStatusReport, - sendUnexpectedErrorStatusReport, + sendUnhandledErrorStatusReport, StatusReportBase, getActionsStatus, ActionName, @@ -173,7 +173,7 @@ async function runWrapper() { core.setFailed( `codeql/upload-sarif action failed: ${getErrorMessage(error)}`, ); - await sendUnexpectedErrorStatusReport( + await sendUnhandledErrorStatusReport( ActionName.UploadSarif, startedAt, error, From 529c266223a58cd393dfc219b43361393a51887f Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 23 Jan 2026 10:36:25 +0000 Subject: [PATCH 06/10] Use `getErrorMessage` in more places --- lib/analyze-action.js | 8 +++++--- lib/autobuild-action.js | 8 +++++--- lib/init-action-post.js | 8 +++++--- lib/init-action.js | 8 +++++--- lib/resolve-environment-action.js | 8 +++++--- lib/setup-codeql-action.js | 8 +++++--- lib/start-proxy-action.js | 8 +++++--- lib/upload-sarif-action.js | 8 +++++--- src/status-report.ts | 8 +++++--- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index c8bd4aed09..e45e67a6a5 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -94309,7 +94309,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -94347,7 +94349,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -94427,7 +94429,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 09722eb202..57885eac39 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -88781,7 +88781,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -88819,7 +88821,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -88899,7 +88901,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 9bc9c637fb..5034549b06 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -130672,7 +130672,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -130710,7 +130712,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -130790,7 +130792,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/init-action.js b/lib/init-action.js index 382979c844..67df79fef2 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92100,7 +92100,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -92138,7 +92140,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -92264,7 +92266,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 86069a98ac..032e47b970 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -88401,7 +88401,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -88439,7 +88441,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -88519,7 +88521,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 4385b012c8..100459b82d 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89728,7 +89728,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -89766,7 +89768,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -89846,7 +89848,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 21a7e0341b..aba9e48bb3 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104565,7 +104565,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -104603,7 +104605,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -104683,7 +104685,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index c2d42c4f04..61826c285b 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -90958,7 +90958,9 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.` + ); } if (config) { statusReport.languages = config.languages?.join(","); @@ -90996,7 +90998,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.` + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.` ); if (isInTestMode()) { throw e; @@ -91076,7 +91078,7 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.` + `Failed to send the error status report: ${getErrorMessage(e)}.` ); } } diff --git a/src/status-report.ts b/src/status-report.ts index 513cdb43ef..8b9b3a3a96 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -321,7 +321,9 @@ export async function createStatusReportBase( try { statusReport.actions_event_name = getWorkflowEventName(); } catch (e) { - logger.warning(`Could not determine the workflow event name: ${e}.`); + logger.warning( + `Could not determine the workflow event name: ${getErrorMessage(e)}.`, + ); } if (config) { @@ -374,7 +376,7 @@ export async function createStatusReportBase( return statusReport; } catch (e) { logger.warning( - `Caught an exception while gathering information for telemetry: ${e}. Will skip sending status report.`, + `Failed to gather information for telemetry: ${getErrorMessage(e)}. Will skip sending status report.`, ); // Re-throw the exception in test mode. While testing, we want to know if something goes wrong here. @@ -629,7 +631,7 @@ export async function sendUnhandledErrorStatusReport( } } catch (e) { logger.warning( - `Caught an exception while sending the error status report: ${e}.`, + `Failed to send the error status report: ${getErrorMessage(e)}.`, ); } } From edebb7861e8219e81797292963b8dfe2e441587e Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 23 Jan 2026 10:39:51 +0000 Subject: [PATCH 07/10] Differentiate unhandled errors in telemetry --- lib/analyze-action.js | 4 ++-- lib/autobuild-action.js | 4 ++-- lib/init-action-post.js | 4 ++-- lib/init-action.js | 4 ++-- lib/resolve-environment-action.js | 4 ++-- lib/setup-codeql-action.js | 4 ++-- lib/start-proxy-action.js | 4 ++-- lib/upload-sarif-action.js | 4 ++-- src/status-report.ts | 6 ++++-- 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index e45e67a6a5..9bfae0b60a 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -94421,8 +94421,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 57885eac39..a04c642862 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -88893,8 +88893,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 5034549b06..dd4513a9b2 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -130784,8 +130784,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/init-action.js b/lib/init-action.js index 67df79fef2..12c7c73cf0 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92258,8 +92258,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 032e47b970..dc3903dc7a 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -88513,8 +88513,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 100459b82d..a31eac0fe0 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89840,8 +89840,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index aba9e48bb3..eb5f9a8f66 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104677,8 +104677,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 61826c285b..7857564f5d 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -91070,8 +91070,8 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - void 0, - getErrorMessage(error3) + `Unhandled error: ${getErrorMessage(error3)}`, + error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); diff --git a/src/status-report.ts b/src/status-report.ts index 8b9b3a3a96..30b50e83d8 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -616,6 +616,8 @@ export async function sendUnhandledErrorStatusReport( logger: Logger, ): Promise { try { + // In the future, we may want to add a specific field for unhandled errors so we can + // create a dedicated monitor for them. const statusReport = await createStatusReportBase( actionName, "failure", @@ -623,8 +625,8 @@ export async function sendUnhandledErrorStatusReport( undefined, undefined, logger, - undefined, - getErrorMessage(error), + `Unhandled error: ${getErrorMessage(error)}`, + error instanceof Error ? error.stack : undefined, ); if (statusReport !== undefined) { await sendStatusReport(statusReport); From 91f34600061a8983d393b3104c28084fbadcb130 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 23 Jan 2026 10:40:51 +0000 Subject: [PATCH 08/10] Throw if in test mode --- lib/analyze-action.js | 7 +++++++ lib/autobuild-action.js | 7 +++++++ lib/init-action-post.js | 7 +++++++ lib/init-action.js | 7 +++++++ lib/resolve-environment-action.js | 7 +++++++ lib/setup-codeql-action.js | 7 +++++++ lib/start-proxy-action.js | 7 +++++++ lib/upload-sarif-action.js | 7 +++++++ src/status-report.ts | 7 +++++++ 9 files changed, 63 insertions(+) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 9bfae0b60a..cb078b4ef6 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -94426,11 +94426,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index a04c642862..842960f50b 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -88898,11 +88898,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/init-action-post.js b/lib/init-action-post.js index dd4513a9b2..3d6a7deb34 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -130789,11 +130789,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/init-action.js b/lib/init-action.js index 12c7c73cf0..e1e3adc6e6 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92263,11 +92263,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index dc3903dc7a..67d710d893 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -88518,11 +88518,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index a31eac0fe0..59605c1fb1 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89845,11 +89845,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index eb5f9a8f66..7a3f66e746 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104682,11 +104682,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 7857564f5d..e5fc6230af 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -91075,11 +91075,18 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error ); if (statusReport !== void 0) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode." + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.` ); + if (isInTestMode()) { + throw e; + } } } diff --git a/src/status-report.ts b/src/status-report.ts index 30b50e83d8..532e692f07 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -630,10 +630,17 @@ export async function sendUnhandledErrorStatusReport( ); if (statusReport !== undefined) { await sendStatusReport(statusReport); + } else if (isInTestMode()) { + throw new Error( + "Failed to create status report for unhandled error in test mode.", + ); } } catch (e) { logger.warning( `Failed to send the error status report: ${getErrorMessage(e)}.`, ); + if (isInTestMode()) { + throw e; + } } } From 28bfb7b7b5f8d7bf79201f61ac2996b0520e94a1 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 23 Jan 2026 10:42:42 +0000 Subject: [PATCH 09/10] Omit error from start-proxy Action --- lib/start-proxy-action.js | 5 +++-- src/start-proxy-action.ts | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 7a3f66e746..93978c2894 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104811,7 +104811,8 @@ async function run(startedAt) { languages: language && [language] }, await checkDiskUsage(logger), - logger + logger, + "Error from start-proxy Action omitted" ); if (errorStatusReportBase !== void 0) { await sendStatusReport(errorStatusReportBase); @@ -104828,7 +104829,7 @@ async function runWrapper() { await sendUnhandledErrorStatusReport( "start-proxy" /* StartProxy */, startedAt, - error3, + new Error("Error from start-proxy Action omitted"), logger ); } diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index e95643bb07..b682d07d30 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -195,6 +195,7 @@ async function run(startedAt: Date) { }, await util.checkDiskUsage(logger), logger, + "Error from start-proxy Action omitted", ); if (errorStatusReportBase !== undefined) { await sendStatusReport(errorStatusReportBase); @@ -213,7 +214,7 @@ async function runWrapper() { await sendUnhandledErrorStatusReport( ActionName.StartProxy, startedAt, - error, + new Error("Error from start-proxy Action omitted"), logger, ); } From fba78720cab61bc9326b24527e56282372bf34d3 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 23 Jan 2026 12:22:31 +0000 Subject: [PATCH 10/10] Address review comments --- lib/analyze-action.js | 8 ++------ lib/autobuild-action.js | 8 ++------ lib/init-action-post.js | 8 ++------ lib/init-action.js | 8 ++------ lib/resolve-environment-action.js | 8 ++------ lib/setup-codeql-action.js | 8 ++------ lib/start-proxy-action.js | 8 ++------ lib/upload-sarif-action.js | 8 ++------ src/status-report.ts | 8 ++------ 9 files changed, 18 insertions(+), 54 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index cb078b4ef6..f2f71755f2 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -94421,19 +94421,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 842960f50b..bf18e8f556 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -88893,19 +88893,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 3d6a7deb34..3d35e98242 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -130784,19 +130784,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/init-action.js b/lib/init-action.js index e1e3adc6e6..34a3a1086f 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92258,19 +92258,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 67d710d893..239f35bcdb 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -88513,19 +88513,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 59605c1fb1..6af67bc086 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -89840,19 +89840,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 93978c2894..16809bda36 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104677,19 +104677,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index e5fc6230af..6bd0faaded 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -91070,19 +91070,15 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error void 0, void 0, logger, - `Unhandled error: ${getErrorMessage(error3)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error3)}`, error3 instanceof Error ? error3.stack : void 0 ); if (statusReport !== void 0) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode." - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.` + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.` ); if (isInTestMode()) { throw e; diff --git a/src/status-report.ts b/src/status-report.ts index 532e692f07..4471b3ce9f 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -625,19 +625,15 @@ export async function sendUnhandledErrorStatusReport( undefined, undefined, logger, - `Unhandled error: ${getErrorMessage(error)}`, + `Unhandled CodeQL Action error: ${getErrorMessage(error)}`, error instanceof Error ? error.stack : undefined, ); if (statusReport !== undefined) { await sendStatusReport(statusReport); - } else if (isInTestMode()) { - throw new Error( - "Failed to create status report for unhandled error in test mode.", - ); } } catch (e) { logger.warning( - `Failed to send the error status report: ${getErrorMessage(e)}.`, + `Failed to send the unhandled error status report: ${getErrorMessage(e)}.`, ); if (isInTestMode()) { throw e;